backup 3.0.2 → 3.0.3.build.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/backup +12 -190
- metadata +7 -191
- data/.gitignore +0 -2
- data/.infinity_test +0 -7
- data/.rspec +0 -3
- data/Gemfile +0 -17
- data/Gemfile.lock +0 -88
- data/LICENSE.md +0 -24
- data/README.md +0 -236
- data/backup.gemspec +0 -41
- data/lib/backup.rb +0 -148
- data/lib/backup/archive.rb +0 -54
- data/lib/backup/cli.rb +0 -50
- data/lib/backup/compressor/base.rb +0 -17
- data/lib/backup/compressor/gzip.rb +0 -61
- data/lib/backup/configuration/base.rb +0 -15
- data/lib/backup/configuration/compressor/base.rb +0 -10
- data/lib/backup/configuration/compressor/gzip.rb +0 -23
- data/lib/backup/configuration/database/base.rb +0 -18
- data/lib/backup/configuration/database/mongodb.rb +0 -37
- data/lib/backup/configuration/database/mysql.rb +0 -37
- data/lib/backup/configuration/database/postgresql.rb +0 -37
- data/lib/backup/configuration/database/redis.rb +0 -35
- data/lib/backup/configuration/encryptor/base.rb +0 -10
- data/lib/backup/configuration/encryptor/gpg.rb +0 -17
- data/lib/backup/configuration/encryptor/open_ssl.rb +0 -26
- data/lib/backup/configuration/helpers.rb +0 -54
- data/lib/backup/configuration/notifier/base.rb +0 -39
- data/lib/backup/configuration/notifier/mail.rb +0 -52
- data/lib/backup/configuration/storage/base.rb +0 -18
- data/lib/backup/configuration/storage/cloudfiles.rb +0 -21
- data/lib/backup/configuration/storage/dropbox.rb +0 -25
- data/lib/backup/configuration/storage/ftp.rb +0 -25
- data/lib/backup/configuration/storage/rsync.rb +0 -25
- data/lib/backup/configuration/storage/s3.rb +0 -25
- data/lib/backup/configuration/storage/scp.rb +0 -25
- data/lib/backup/configuration/storage/sftp.rb +0 -25
- data/lib/backup/database/base.rb +0 -33
- data/lib/backup/database/mongodb.rb +0 -137
- data/lib/backup/database/mysql.rb +0 -104
- data/lib/backup/database/postgresql.rb +0 -111
- data/lib/backup/database/redis.rb +0 -105
- data/lib/backup/encryptor/base.rb +0 -17
- data/lib/backup/encryptor/gpg.rb +0 -78
- data/lib/backup/encryptor/open_ssl.rb +0 -67
- data/lib/backup/finder.rb +0 -39
- data/lib/backup/logger.rb +0 -80
- data/lib/backup/model.rb +0 -249
- data/lib/backup/notifier/base.rb +0 -29
- data/lib/backup/notifier/binder.rb +0 -32
- data/lib/backup/notifier/mail.rb +0 -141
- data/lib/backup/notifier/templates/notify_failure.erb +0 -31
- data/lib/backup/notifier/templates/notify_success.erb +0 -16
- data/lib/backup/storage/base.rb +0 -67
- data/lib/backup/storage/cloudfiles.rb +0 -95
- data/lib/backup/storage/dropbox.rb +0 -82
- data/lib/backup/storage/ftp.rb +0 -114
- data/lib/backup/storage/object.rb +0 -45
- data/lib/backup/storage/rsync.rb +0 -100
- data/lib/backup/storage/s3.rb +0 -108
- data/lib/backup/storage/scp.rb +0 -105
- data/lib/backup/storage/sftp.rb +0 -106
- data/lib/backup/version.rb +0 -72
- data/lib/templates/archive +0 -4
- data/lib/templates/compressor/gzip +0 -4
- data/lib/templates/database/mongodb +0 -10
- data/lib/templates/database/mysql +0 -11
- data/lib/templates/database/postgresql +0 -11
- data/lib/templates/database/redis +0 -10
- data/lib/templates/encryptor/gpg +0 -9
- data/lib/templates/encryptor/openssl +0 -5
- data/lib/templates/notifier/mail +0 -14
- data/lib/templates/readme +0 -15
- data/lib/templates/storage/cloudfiles +0 -7
- data/lib/templates/storage/dropbox +0 -8
- data/lib/templates/storage/ftp +0 -8
- data/lib/templates/storage/rsync +0 -7
- data/lib/templates/storage/s3 +0 -8
- data/lib/templates/storage/scp +0 -8
- data/lib/templates/storage/sftp +0 -8
- data/spec/archive_spec.rb +0 -53
- data/spec/backup_spec.rb +0 -11
- data/spec/compressor/gzip_spec.rb +0 -59
- data/spec/configuration/base_spec.rb +0 -35
- data/spec/configuration/compressor/gzip_spec.rb +0 -28
- data/spec/configuration/database/base_spec.rb +0 -16
- data/spec/configuration/database/mongodb_spec.rb +0 -30
- data/spec/configuration/database/mysql_spec.rb +0 -32
- data/spec/configuration/database/postgresql_spec.rb +0 -32
- data/spec/configuration/database/redis_spec.rb +0 -30
- data/spec/configuration/encryptor/gpg_spec.rb +0 -25
- data/spec/configuration/encryptor/open_ssl_spec.rb +0 -31
- data/spec/configuration/notifier/mail_spec.rb +0 -32
- data/spec/configuration/storage/cloudfiles_spec.rb +0 -34
- data/spec/configuration/storage/dropbox_spec.rb +0 -40
- data/spec/configuration/storage/ftp_spec.rb +0 -40
- data/spec/configuration/storage/rsync_spec.rb +0 -37
- data/spec/configuration/storage/s3_spec.rb +0 -37
- data/spec/configuration/storage/scp_spec.rb +0 -40
- data/spec/configuration/storage/sftp_spec.rb +0 -40
- data/spec/database/base_spec.rb +0 -30
- data/spec/database/mongodb_spec.rb +0 -144
- data/spec/database/mysql_spec.rb +0 -150
- data/spec/database/postgresql_spec.rb +0 -164
- data/spec/database/redis_spec.rb +0 -122
- data/spec/encryptor/gpg_spec.rb +0 -57
- data/spec/encryptor/open_ssl_spec.rb +0 -102
- data/spec/logger_spec.rb +0 -37
- data/spec/model_spec.rb +0 -236
- data/spec/notifier/mail_spec.rb +0 -97
- data/spec/spec_helper.rb +0 -21
- data/spec/storage/base_spec.rb +0 -33
- data/spec/storage/cloudfiles_spec.rb +0 -102
- data/spec/storage/dropbox_spec.rb +0 -89
- data/spec/storage/ftp_spec.rb +0 -133
- data/spec/storage/object_spec.rb +0 -74
- data/spec/storage/rsync_spec.rb +0 -115
- data/spec/storage/s3_spec.rb +0 -110
- data/spec/storage/scp_spec.rb +0 -129
- data/spec/storage/sftp_spec.rb +0 -125
- data/spec/version_spec.rb +0 -32
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
There seemed to be a problem backing up <%= @model.label %> (<%= @model.trigger %>).
|
|
3
|
-
|
|
4
|
-
===========================================================================
|
|
5
|
-
Exception that got raised:
|
|
6
|
-
<%= @exception.to_s %>
|
|
7
|
-
===========================================================================
|
|
8
|
-
<%= @exception.backtrace.join("\n") %>
|
|
9
|
-
===========================================================================
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
You are running Backup version:
|
|
13
|
-
<%= Backup::Version.current %>
|
|
14
|
-
|
|
15
|
-
You are running Ruby version:
|
|
16
|
-
<%= ENV["RUBY_VERSION"] %>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
---------------------------------------------------------------------------
|
|
20
|
-
|
|
21
|
-
View all Backup gem releases here:
|
|
22
|
-
http://rubygems.org/gems/backup
|
|
23
|
-
|
|
24
|
-
View the Backup git repository here:
|
|
25
|
-
https://github.com/meskyanichi/backup
|
|
26
|
-
|
|
27
|
-
View the Backup issues here:
|
|
28
|
-
https://github.com/meskyanichi/backup/issues
|
|
29
|
-
|
|
30
|
-
View the Backup wiki here:
|
|
31
|
-
https://github.com/meskyanichi/backup/wiki
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Backup <%= @model.label %> (<%= @model.trigger %>) finished without any errors!
|
|
3
|
-
|
|
4
|
-
---------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
View all Backup gem releases here:
|
|
7
|
-
http://rubygems.org/gems/backup
|
|
8
|
-
|
|
9
|
-
View the Backup git repository here:
|
|
10
|
-
https://github.com/meskyanichi/backup
|
|
11
|
-
|
|
12
|
-
View the Backup issues here:
|
|
13
|
-
https://github.com/meskyanichi/backup/issues
|
|
14
|
-
|
|
15
|
-
View the Backup wiki here:
|
|
16
|
-
https://github.com/meskyanichi/backup/wiki
|
data/lib/backup/storage/base.rb
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Storage
|
|
5
|
-
class Base
|
|
6
|
-
include Backup::Configuration::Helpers
|
|
7
|
-
|
|
8
|
-
##
|
|
9
|
-
# The time when the backup initiated (in format: 2011.02.20.03.29.59)
|
|
10
|
-
attr_accessor :time
|
|
11
|
-
|
|
12
|
-
##
|
|
13
|
-
# Sets the limit to how many backups to keep in the remote location.
|
|
14
|
-
# If the limit exceeds it will remove the oldest backup to make room for the newest
|
|
15
|
-
attr_accessor :keep
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# Returns the local path
|
|
19
|
-
def local_path
|
|
20
|
-
TMP_PATH
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
##
|
|
24
|
-
# Returns the local archive filename
|
|
25
|
-
def local_file
|
|
26
|
-
@local_file ||= File.basename(Backup::Model.file)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
##
|
|
30
|
-
# Returns the name of the file that's stored on the remote location
|
|
31
|
-
def remote_file
|
|
32
|
-
@remote_file ||= local_file
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
##
|
|
36
|
-
# Provider defaults to false and will be overridden when using
|
|
37
|
-
# a service-based storage such as Amazon S3, Rackspace Cloud Files or Dropbox
|
|
38
|
-
def provider
|
|
39
|
-
false
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
##
|
|
43
|
-
# Checks the persisted storage data by type (S3, CloudFiles, SCP, etc)
|
|
44
|
-
# to see if the amount of stored backups is greater than the amount of
|
|
45
|
-
# backups allowed. If this is the case it'll invoke the #remove! method
|
|
46
|
-
# on each of the oldest backups that exceed the storage limit (specified by @keep).
|
|
47
|
-
# After that it'll re-assign the objects variable with an array of objects that still remain
|
|
48
|
-
# after the removal of the older objects and files (that exceeded the @keep range). And finally
|
|
49
|
-
# these remaining objects will be converted to YAML format and are written back to the YAML file
|
|
50
|
-
def cycle!
|
|
51
|
-
type = self.class.name.split("::").last
|
|
52
|
-
storage_object = Backup::Storage::Object.new(type)
|
|
53
|
-
objects = [self] + storage_object.load
|
|
54
|
-
if keep.is_a?(Integer) and keep > 0 and objects.count > keep
|
|
55
|
-
objects_to_remove = objects[keep..-1]
|
|
56
|
-
objects_to_remove.each do |object|
|
|
57
|
-
Logger.message "#{ self.class } started removing (cycling) \"#{ object.remote_file }\"."
|
|
58
|
-
object.send(:remove!)
|
|
59
|
-
end
|
|
60
|
-
objects = objects - objects_to_remove
|
|
61
|
-
end
|
|
62
|
-
storage_object.write(objects)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# Only load the Fog gem when the Backup::Storage::CloudFiles class is loaded
|
|
5
|
-
require 'fog'
|
|
6
|
-
|
|
7
|
-
module Backup
|
|
8
|
-
module Storage
|
|
9
|
-
class CloudFiles < Base
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
# Rackspace Cloud Files Credentials
|
|
13
|
-
attr_accessor :username, :api_key
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
# Rackspace Cloud Files container name and path
|
|
17
|
-
attr_accessor :container, :path
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
# Creates a new instance of the Rackspace Cloud Files storage object
|
|
21
|
-
# First it sets the defaults (if any exist) and then evaluates
|
|
22
|
-
# the configuration block which may overwrite these defaults
|
|
23
|
-
def initialize(&block)
|
|
24
|
-
load_defaults!
|
|
25
|
-
|
|
26
|
-
@path ||= 'backups'
|
|
27
|
-
|
|
28
|
-
instance_eval(&block) if block_given?
|
|
29
|
-
|
|
30
|
-
@time = TIME
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
##
|
|
34
|
-
# This is the remote path to where the backup files will be stored
|
|
35
|
-
def remote_path
|
|
36
|
-
File.join(path, TRIGGER)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
##
|
|
40
|
-
# This is the provider that Fog uses for the Cloud Files Storage
|
|
41
|
-
def provider
|
|
42
|
-
'Rackspace'
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
##
|
|
46
|
-
# Performs the backup transfer
|
|
47
|
-
def perform!
|
|
48
|
-
transfer!
|
|
49
|
-
cycle!
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
##
|
|
55
|
-
# Establishes a connection to Rackspace Cloud Files and returns the Fog object.
|
|
56
|
-
# Not doing any instance variable caching because this object gets persisted in YAML
|
|
57
|
-
# format to a file and will issues. This, however has no impact on performance since it only
|
|
58
|
-
# gets invoked once per object for a #transfer! and once for a remove! Backups run in the
|
|
59
|
-
# background anyway so even if it were a bit slower it shouldn't matter.
|
|
60
|
-
def connection
|
|
61
|
-
Fog::Storage.new(
|
|
62
|
-
:provider => provider,
|
|
63
|
-
:rackspace_username => username,
|
|
64
|
-
:rackspace_api_key => api_key
|
|
65
|
-
)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
##
|
|
69
|
-
# Transfers the archived file to the specified Cloud Files container
|
|
70
|
-
def transfer!
|
|
71
|
-
begin
|
|
72
|
-
Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
|
|
73
|
-
connection.put_object(
|
|
74
|
-
container,
|
|
75
|
-
File.join(remote_path, remote_file),
|
|
76
|
-
File.open(File.join(local_path, local_file))
|
|
77
|
-
)
|
|
78
|
-
rescue Excon::Errors::SocketError => e
|
|
79
|
-
puts "\nAn error occurred while trying to transfer the backup."
|
|
80
|
-
puts "Make sure the container exists and try again.\n\n"
|
|
81
|
-
exit
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
##
|
|
86
|
-
# Removes the transferred archive file from the Cloud Files container
|
|
87
|
-
def remove!
|
|
88
|
-
begin
|
|
89
|
-
connection.delete_object(container, File.join(remote_path, remote_file))
|
|
90
|
-
rescue Excon::Errors::SocketError; end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# Only load the Dropbox gem when the Backup::Storage::Dropbox class is loaded
|
|
5
|
-
require 'dropbox'
|
|
6
|
-
|
|
7
|
-
module Backup
|
|
8
|
-
module Storage
|
|
9
|
-
class Dropbox < Base
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
# Dropbox user credentials
|
|
13
|
-
attr_accessor :email, :password
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
# Dropbox API credentials
|
|
17
|
-
attr_accessor :api_key, :api_secret
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
# Path to where the backups will be stored
|
|
21
|
-
attr_accessor :path
|
|
22
|
-
|
|
23
|
-
##
|
|
24
|
-
# Creates a new instance of the Dropbox storage object
|
|
25
|
-
# First it sets the defaults (if any exist) and then evaluates
|
|
26
|
-
# the configuration block which may overwrite these defaults
|
|
27
|
-
def initialize(&block)
|
|
28
|
-
load_defaults!
|
|
29
|
-
|
|
30
|
-
@path ||= 'backups'
|
|
31
|
-
|
|
32
|
-
instance_eval(&block) if block_given?
|
|
33
|
-
|
|
34
|
-
@time = TIME
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
##
|
|
38
|
-
# This is the remote path to where the backup files will be stored
|
|
39
|
-
def remote_path
|
|
40
|
-
File.join(path, TRIGGER)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
##
|
|
44
|
-
# Performs the backup transfer
|
|
45
|
-
def perform!
|
|
46
|
-
transfer!
|
|
47
|
-
cycle!
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
private
|
|
51
|
-
|
|
52
|
-
##
|
|
53
|
-
# Establishes a connection to Dropbox and returns the Dropbox::Session object.
|
|
54
|
-
# Not doing any instance variable caching because this object gets persisted in YAML
|
|
55
|
-
# format to a file and will issues. This, however has no impact on performance since it only
|
|
56
|
-
# gets invoked once per object for a #transfer! and once for a remove! Backups run in the
|
|
57
|
-
# background anyway so even if it were a bit slower it shouldn't matter.
|
|
58
|
-
def connection
|
|
59
|
-
session = ::Dropbox::Session.new(api_key, api_secret)
|
|
60
|
-
session.mode = :dropbox
|
|
61
|
-
session.authorizing_user = email
|
|
62
|
-
session.authorizing_password = password
|
|
63
|
-
session.authorize!
|
|
64
|
-
session
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
##
|
|
68
|
-
# Transfers the archived file to the specified Dropbox folder
|
|
69
|
-
def transfer!
|
|
70
|
-
Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
|
|
71
|
-
connection.upload(File.join(local_path, local_file), remote_path, :timeout => 300)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
##
|
|
75
|
-
# Removes the transferred archive file from the Dropbox folder
|
|
76
|
-
def remove!
|
|
77
|
-
connection.delete(File.join(remote_path, remote_file))
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
data/lib/backup/storage/ftp.rb
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# Only load the Net::FTP library/gem when the Backup::Storage::FTP class is loaded
|
|
5
|
-
require 'net/ftp'
|
|
6
|
-
|
|
7
|
-
module Backup
|
|
8
|
-
module Storage
|
|
9
|
-
class FTP < Base
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
# Server credentials
|
|
13
|
-
attr_accessor :username, :password
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
# Server IP Address and FTP port
|
|
17
|
-
attr_accessor :ip, :port
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
# Path to store backups to
|
|
21
|
-
attr_accessor :path
|
|
22
|
-
|
|
23
|
-
##
|
|
24
|
-
# Creates a new instance of the FTP storage object
|
|
25
|
-
# First it sets the defaults (if any exist) and then evaluates
|
|
26
|
-
# the configuration block which may overwrite these defaults
|
|
27
|
-
def initialize(&block)
|
|
28
|
-
load_defaults!
|
|
29
|
-
|
|
30
|
-
@port ||= 21
|
|
31
|
-
@path ||= 'backups'
|
|
32
|
-
|
|
33
|
-
instance_eval(&block) if block_given?
|
|
34
|
-
|
|
35
|
-
@time = TIME
|
|
36
|
-
@path = path.sub(/^\~\//, '')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
##
|
|
40
|
-
# This is the remote path to where the backup files will be stored
|
|
41
|
-
def remote_path
|
|
42
|
-
File.join(path, TRIGGER)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
##
|
|
46
|
-
# Performs the backup transfer
|
|
47
|
-
def perform!
|
|
48
|
-
transfer!
|
|
49
|
-
cycle!
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
##
|
|
55
|
-
# Establishes a connection to the remote server and returns the Net::FTP object.
|
|
56
|
-
# Not doing any instance variable caching because this object gets persisted in YAML
|
|
57
|
-
# format to a file and will issues. This, however has no impact on performance since it only
|
|
58
|
-
# gets invoked once per object for a #transfer! and once for a remove! Backups run in the
|
|
59
|
-
# background anyway so even if it were a bit slower it shouldn't matter.
|
|
60
|
-
#
|
|
61
|
-
# Note *
|
|
62
|
-
# Since the FTP port is defined as a constant in the Net::FTP class, and might be required
|
|
63
|
-
# to change by the user, we dynamically remove and re-add the constant with the provided port value
|
|
64
|
-
def connection
|
|
65
|
-
if defined? Net::FTP::FTP_PORT
|
|
66
|
-
Net::FTP.send(:remove_const, :FTP_PORT)
|
|
67
|
-
end; Net::FTP.send(:const_set, :FTP_PORT, port)
|
|
68
|
-
|
|
69
|
-
Net::FTP.new(ip, username, password)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
##
|
|
73
|
-
# Transfers the archived file to the specified remote server
|
|
74
|
-
def transfer!
|
|
75
|
-
Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
|
|
76
|
-
create_remote_directories!
|
|
77
|
-
connection.put(
|
|
78
|
-
File.join(local_path, local_file),
|
|
79
|
-
File.join(remote_path, remote_file)
|
|
80
|
-
)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
##
|
|
84
|
-
# Removes the transferred archive file from the server
|
|
85
|
-
def remove!
|
|
86
|
-
begin
|
|
87
|
-
connection.delete(
|
|
88
|
-
File.join(remote_path, remote_file)
|
|
89
|
-
)
|
|
90
|
-
rescue Net::FTPPermError
|
|
91
|
-
Logger.warn "Could not remove file \"#{ File.join(remote_path, remote_file) }\"."
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
##
|
|
96
|
-
# Creates (if they don't exist yet) all the directories on the remote
|
|
97
|
-
# server in order to upload the backup file. Net::FTP does not support
|
|
98
|
-
# paths to directories that don't yet exist when creating new directories.
|
|
99
|
-
# Instead, we split the parts up in to an array (for each '/') and loop through
|
|
100
|
-
# that to create the directories one by one. Net::FTP raises an exception when
|
|
101
|
-
# the directory it's trying ot create already exists, so we have rescue it
|
|
102
|
-
def create_remote_directories!
|
|
103
|
-
path_parts = Array.new
|
|
104
|
-
remote_path.split('/').each do |path_part|
|
|
105
|
-
path_parts << path_part
|
|
106
|
-
begin
|
|
107
|
-
connection.mkdir(path_parts.join('/'))
|
|
108
|
-
rescue Net::FTPPermError; end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Storage
|
|
5
|
-
class Object
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
# Holds the type attribute
|
|
9
|
-
attr_accessor :storage_file
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
# Instantiates a new Backup::Storage::Object and stores the
|
|
13
|
-
# full path to the storage file (yaml) in the @storage_file attribute
|
|
14
|
-
def initialize(type)
|
|
15
|
-
@storage_file = File.join(DATA_PATH, TRIGGER, "#{type}.yml")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
# Tries to load an existing YAML file and returns an
|
|
20
|
-
# array of storage objects. If no file exists, an empty
|
|
21
|
-
# array gets returned
|
|
22
|
-
#
|
|
23
|
-
# If a file is loaded it'll sort the array of objects by @time
|
|
24
|
-
# descending. The newest backup storage object comes in Backup::Storage::Object.load[0]
|
|
25
|
-
# and the oldest in Backup::Storage::Object.load[-1]
|
|
26
|
-
def load
|
|
27
|
-
if File.exist?(storage_file)
|
|
28
|
-
YAML.load_file(storage_file).sort { |a,b| b.time <=> a.time }
|
|
29
|
-
else
|
|
30
|
-
[]
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
##
|
|
35
|
-
# Takes the provided objects and converts it to YAML format.
|
|
36
|
-
# The YAML data gets written to the storage file
|
|
37
|
-
def write(objects)
|
|
38
|
-
File.open(storage_file, 'w') do |file|
|
|
39
|
-
file.write(objects.to_yaml)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|