backup 3.0.20 → 3.0.21
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/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
data/lib/backup/cleaner.rb
CHANGED
|
@@ -1,36 +1,121 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
|
|
3
3
|
module Backup
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
module Cleaner
|
|
5
|
+
class << self
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
##
|
|
8
|
+
# Logs warnings if any temporary files still exist
|
|
9
|
+
# from the last time this model/trigger was run,
|
|
10
|
+
# then removes the files.
|
|
11
|
+
def prepare(model)
|
|
12
|
+
@model = model
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
messages = []
|
|
15
|
+
if packaging_folder_dirty?
|
|
16
|
+
messages << <<-EOS
|
|
17
|
+
The temporary backup folder still contains files!
|
|
18
|
+
'#{ File.join(Config.tmp_path, @model.trigger) }'
|
|
19
|
+
These files will now be removed.
|
|
20
|
+
EOS
|
|
21
|
+
FileUtils.rm_rf(File.join(Config.tmp_path, @model.trigger))
|
|
22
|
+
end
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
package_files = tmp_path_package_files
|
|
25
|
+
unless package_files.empty?
|
|
26
|
+
# the chances that tmp_path would be dirty
|
|
27
|
+
# AND package files exist are practically nil
|
|
28
|
+
messages << ('-' * 74) unless messages.empty?
|
|
29
|
+
|
|
30
|
+
messages << <<-EOS
|
|
31
|
+
The temporary backup folder '#{ Config.tmp_path }'
|
|
32
|
+
appears to contain the package files from the previous backup!
|
|
33
|
+
#{ package_files.join("\n") }
|
|
34
|
+
These files will now be removed.
|
|
35
|
+
EOS
|
|
36
|
+
package_files.each {|file| FileUtils.rm_f(file) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
unless messages.empty?
|
|
40
|
+
Logger.warn Errors::CleanerError.new(<<-EOS)
|
|
41
|
+
Cleanup Warning
|
|
42
|
+
#{ messages.join("\n") }
|
|
43
|
+
Please check the log for messages and/or your notifications
|
|
44
|
+
concerning this backup: '#{ @model.label } (#{ @model.trigger })'
|
|
45
|
+
The temporary files which had to be removed should not have existed.
|
|
46
|
+
EOS
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
##
|
|
51
|
+
# Remove the temporary folder used during packaging
|
|
52
|
+
def remove_packaging(model)
|
|
53
|
+
Logger.message "Cleaning up the temporary files..."
|
|
54
|
+
FileUtils.rm_rf(File.join(Config.tmp_path, model.trigger))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
##
|
|
58
|
+
# Remove the final package files from tmp_path
|
|
59
|
+
# Note: 'force' is used, since a Local Storage may *move* these files.
|
|
60
|
+
def remove_package(package)
|
|
61
|
+
Logger.message "Cleaning up the package files..."
|
|
62
|
+
package.filenames.each do |file|
|
|
63
|
+
FileUtils.rm_f(File.join(Config.tmp_path, file))
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
##
|
|
68
|
+
# Logs warnings if any temporary files still exist
|
|
69
|
+
# when errors occur during the backup
|
|
70
|
+
def warnings(model)
|
|
71
|
+
@model = model
|
|
72
|
+
|
|
73
|
+
messages = []
|
|
74
|
+
if packaging_folder_dirty?
|
|
75
|
+
messages << <<-EOS
|
|
76
|
+
The temporary backup folder still contains files!
|
|
77
|
+
'#{ File.join(Config.tmp_path, @model.trigger) }'
|
|
78
|
+
This folder may contain completed Archives and/or Database backups.
|
|
79
|
+
EOS
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
package_files = tmp_path_package_files
|
|
83
|
+
unless package_files.empty?
|
|
84
|
+
# the chances that tmp_path would be dirty
|
|
85
|
+
# AND package files exist are practically nil
|
|
86
|
+
messages << ('-' * 74) unless messages.empty?
|
|
87
|
+
|
|
88
|
+
messages << <<-EOS
|
|
89
|
+
The temporary backup folder '#{ Config.tmp_path }'
|
|
90
|
+
appears to contain the backup files which were to be stored:
|
|
91
|
+
#{ package_files.join("\n") }
|
|
92
|
+
EOS
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
unless messages.empty?
|
|
96
|
+
Logger.warn Errors::CleanerError.new(<<-EOS)
|
|
97
|
+
Cleanup Warning
|
|
98
|
+
#{ messages.join("\n") }
|
|
99
|
+
Make sure you check these files before the next scheduled backup for
|
|
100
|
+
'#{ @model.label } (#{ @model.trigger })'
|
|
101
|
+
These files will be removed at that time!
|
|
102
|
+
EOS
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
private
|
|
107
|
+
|
|
108
|
+
def packaging_folder_dirty?
|
|
109
|
+
!Dir[File.join(Config.tmp_path, @model.trigger, '*')].empty?
|
|
110
|
+
end
|
|
23
111
|
|
|
24
|
-
|
|
112
|
+
def tmp_path_package_files
|
|
113
|
+
Dir[File.join(
|
|
114
|
+
Config.tmp_path,
|
|
115
|
+
"????.??.??.??.??.??.#{ @model.trigger }.tar{,[.-]*}"
|
|
116
|
+
)]
|
|
117
|
+
end
|
|
25
118
|
|
|
26
|
-
##
|
|
27
|
-
# Returns an Array of paths to temporary files generated by Backup that need to be removed
|
|
28
|
-
def paths
|
|
29
|
-
Array.new([
|
|
30
|
-
File.join(TMP_PATH, TRIGGER),
|
|
31
|
-
Backup::Model.file,
|
|
32
|
-
Backup::Model.chunk_suffixes.map { |chunk_suffix| "#{Backup::Model.file}-#{chunk_suffix}" }
|
|
33
|
-
]).flatten
|
|
34
119
|
end
|
|
35
120
|
end
|
|
36
121
|
end
|
data/lib/backup/cli/helpers.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
module Backup
|
|
4
4
|
module CLI
|
|
5
5
|
module Helpers
|
|
6
|
+
UTILITY = {}
|
|
6
7
|
|
|
7
8
|
##
|
|
8
9
|
# Runs a given command in an isolated (sub) process using POpen4.
|
|
@@ -33,44 +34,28 @@ module Backup
|
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
##
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
# improves readability
|
|
39
|
-
def mkdir(path)
|
|
40
|
-
FileUtils.mkdir_p(path)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
##
|
|
44
|
-
# Wrapper for the FileUtils.rm_rf to remove files and folders
|
|
45
|
-
# through a ruby method. This helps with test coverage and
|
|
46
|
-
# improves readability
|
|
47
|
-
def rm(path)
|
|
48
|
-
FileUtils.rm_rf(path)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
##
|
|
52
|
-
# Tries to find the full path of the specified utility. If the full
|
|
53
|
-
# path is found, it'll return that. Otherwise it'll just return the
|
|
54
|
-
# name of the utility. If the 'utility_path' is defined, it'll check
|
|
55
|
-
# to see if it isn't an empty string, and if it isn't, it'll go ahead and
|
|
56
|
-
# always use that path rather than auto-detecting it
|
|
37
|
+
# Returns the full path to the specified utility.
|
|
38
|
+
# Raises an error if utility can not be found in the system's $PATH
|
|
57
39
|
def utility(name)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
40
|
+
path = UTILITY[name] || %x[which #{name} 2>/dev/null].chomp
|
|
41
|
+
if path.empty?
|
|
42
|
+
raise Errors::CLI::UtilityNotFoundError, <<-EOS
|
|
43
|
+
Path to '#{ name }' could not be found.
|
|
44
|
+
Make sure the specified utility is installed
|
|
45
|
+
and available in your system's $PATH.
|
|
46
|
+
If this is a database utility, you may need to specify the full path
|
|
47
|
+
using the Database's '<utility_name>_utility' configuration setting.
|
|
48
|
+
EOS
|
|
66
49
|
end
|
|
67
|
-
name
|
|
50
|
+
UTILITY[name] = path
|
|
68
51
|
end
|
|
69
52
|
|
|
70
53
|
##
|
|
71
|
-
# Returns the name of the command
|
|
54
|
+
# Returns the name of the command name from the given command line
|
|
72
55
|
def command_name(command)
|
|
73
|
-
command
|
|
56
|
+
i = command =~ /\s/
|
|
57
|
+
command = command.slice(0, i) if i
|
|
58
|
+
command.split('/')[-1]
|
|
74
59
|
end
|
|
75
60
|
|
|
76
61
|
##
|
data/lib/backup/cli/utility.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Backup
|
|
|
13
13
|
# If the other options (--config-file, --data-path, --cache--path, --tmp-path) aren't specified
|
|
14
14
|
# they will fallback to the (good) defaults
|
|
15
15
|
#
|
|
16
|
-
# If --root-path is given, it will be used as the base
|
|
16
|
+
# If --root-path is given, it will be used as the base path for our defaults,
|
|
17
17
|
# as well as the base path for any option specified as a relative path.
|
|
18
18
|
# Any option given as an absolute path will be used "as-is".
|
|
19
19
|
method_option :trigger, :type => :string, :required => true, :aliases => ['-t', '--triggers']
|
|
@@ -30,71 +30,56 @@ module Backup
|
|
|
30
30
|
"This will invoke 4 backups, and they will run in the order specified (not asynchronous)."
|
|
31
31
|
def perform
|
|
32
32
|
##
|
|
33
|
-
#
|
|
34
|
-
|
|
33
|
+
# Silence Backup::Logger from printing to STDOUT, if --quiet was specified
|
|
34
|
+
Logger.quiet = options[:quiet]
|
|
35
35
|
|
|
36
36
|
##
|
|
37
|
-
#
|
|
38
|
-
|
|
37
|
+
# Update Config variables based on the given options
|
|
38
|
+
Config.update(options)
|
|
39
|
+
|
|
40
|
+
##
|
|
41
|
+
# Load the configuration file
|
|
42
|
+
Config.load_config!
|
|
43
|
+
|
|
44
|
+
##
|
|
45
|
+
# Ensure the :log_path, :cache_path and :tmp_path are created
|
|
46
|
+
# if they do not yet exist
|
|
47
|
+
[Config.log_path, Config.cache_path, Config.tmp_path].each do |path|
|
|
48
|
+
FileUtils.mkdir_p(path)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
##
|
|
52
|
+
# Truncate log file if needed
|
|
53
|
+
Logger.truncate!
|
|
39
54
|
|
|
40
55
|
##
|
|
41
56
|
# Prepare all trigger names by splitting them by ','
|
|
42
57
|
# and finding trigger names matching wildcard
|
|
43
58
|
triggers = options[:trigger].split(",")
|
|
44
|
-
triggers.map!(&:strip).map!{
|
|
45
|
-
t.include?(
|
|
46
|
-
Backup::Finder.new(t).matching : t
|
|
59
|
+
triggers.map!(&:strip).map! {|t|
|
|
60
|
+
t.include?('*') ? Model.find_matching(t) : t
|
|
47
61
|
}.flatten!
|
|
48
62
|
|
|
49
63
|
##
|
|
50
64
|
# Process each trigger
|
|
51
65
|
triggers.each do |trigger|
|
|
52
|
-
|
|
53
|
-
##
|
|
54
|
-
# Defines the TRIGGER constant
|
|
55
|
-
Backup.send(:const_set, :TRIGGER, trigger)
|
|
56
|
-
|
|
57
66
|
##
|
|
58
|
-
#
|
|
59
|
-
|
|
67
|
+
# Find the model for this trigger
|
|
68
|
+
# Will raise an error if not found
|
|
69
|
+
model = Model.find(trigger)
|
|
60
70
|
|
|
61
71
|
##
|
|
62
|
-
#
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
##
|
|
66
|
-
# Parses the backup configuration file and returns the model instance by trigger
|
|
67
|
-
model = Backup::Finder.new(trigger).find
|
|
68
|
-
|
|
69
|
-
##
|
|
70
|
-
# Runs the returned model
|
|
71
|
-
Logger.message "Performing backup for #{model.label}!"
|
|
72
|
+
# Prepare and Perform the backup
|
|
73
|
+
model.prepare!
|
|
72
74
|
model.perform!
|
|
73
75
|
|
|
74
|
-
##
|
|
75
|
-
# Removes the TRIGGER constant
|
|
76
|
-
Backup.send(:remove_const, :TRIGGER) if defined? Backup::TRIGGER
|
|
77
|
-
|
|
78
|
-
##
|
|
79
|
-
# Removes the TIME constant
|
|
80
|
-
Backup.send(:remove_const, :TIME) if defined? Backup::TIME
|
|
81
|
-
|
|
82
|
-
##
|
|
83
|
-
# Reset the Backup::Model.current to nil for the next potential run
|
|
84
|
-
Backup::Model.current = nil
|
|
85
|
-
|
|
86
76
|
##
|
|
87
77
|
# Clear the Log Messages for the next potential run
|
|
88
78
|
Logger.clear!
|
|
89
|
-
|
|
90
|
-
##
|
|
91
|
-
# Reset the Backup::Model.extension to 'tar' so it's at its
|
|
92
|
-
# initial state when the next Backup::Model initializes
|
|
93
|
-
Backup::Model.extension = 'tar'
|
|
94
79
|
end
|
|
95
80
|
|
|
96
81
|
rescue => err
|
|
97
|
-
Logger.error
|
|
82
|
+
Logger.error Errors::CLIError.wrap(err)
|
|
98
83
|
exit(1)
|
|
99
84
|
end
|
|
100
85
|
|
|
@@ -104,14 +89,15 @@ module Backup
|
|
|
104
89
|
# For example:
|
|
105
90
|
# $ backup generate:model --trigger my_backup --databases='mongodb'
|
|
106
91
|
# will generate a pre-populated model with a base MongoDB setup
|
|
107
|
-
method_option :trigger, :type => :string, :required => true
|
|
108
|
-
method_option :config_path, :type => :string,
|
|
109
|
-
:desc => 'Path to your Backup configuration directory'
|
|
110
92
|
desc 'generate:model', "Generates a Backup model file\n\n" +
|
|
111
93
|
"Note:\n" +
|
|
112
94
|
"\s\s'--config-path' is the path to the directory where 'config.rb' is located.\n" +
|
|
113
95
|
"\s\sThe model file will be created as '<config_path>/models/<trigger>.rb'\n" +
|
|
114
|
-
"\s\sDefault: #{
|
|
96
|
+
"\s\sDefault: #{Config.root_path}\n"
|
|
97
|
+
|
|
98
|
+
method_option :trigger, :type => :string, :required => true
|
|
99
|
+
method_option :config_path, :type => :string,
|
|
100
|
+
:desc => 'Path to your Backup configuration directory'
|
|
115
101
|
|
|
116
102
|
# options with their available values
|
|
117
103
|
%w{ databases storages syncers
|
|
@@ -127,10 +113,11 @@ module Backup
|
|
|
127
113
|
|
|
128
114
|
define_method "generate:model" do
|
|
129
115
|
opts = options.merge(
|
|
130
|
-
:trigger =>
|
|
131
|
-
:config_path =>
|
|
116
|
+
:trigger => options[:trigger].gsub(/[\W\s]/, '_'),
|
|
117
|
+
:config_path => options[:config_path] ?
|
|
118
|
+
File.expand_path(options[:config_path]) : nil
|
|
132
119
|
)
|
|
133
|
-
config_path = opts[:config_path] ||
|
|
120
|
+
config_path = opts[:config_path] || Config.root_path
|
|
134
121
|
models_path = File.join(config_path, "models")
|
|
135
122
|
config = File.join(config_path, "config.rb")
|
|
136
123
|
model = File.join(models_path, "#{opts[:trigger]}.rb")
|
|
@@ -141,14 +128,14 @@ module Backup
|
|
|
141
128
|
file.write(Backup::Template.new({:options => opts}).
|
|
142
129
|
result("cli/utility/model.erb"))
|
|
143
130
|
end
|
|
144
|
-
puts "Generated model file
|
|
131
|
+
puts "Generated model file: '#{ model }'."
|
|
145
132
|
end
|
|
146
133
|
|
|
147
134
|
if not File.exist?(config)
|
|
148
135
|
File.open(config, "w") do |file|
|
|
149
136
|
file.write(Backup::Template.new.result("cli/utility/config"))
|
|
150
137
|
end
|
|
151
|
-
puts "Generated configuration file
|
|
138
|
+
puts "Generated configuration file: '#{ config }'."
|
|
152
139
|
end
|
|
153
140
|
end
|
|
154
141
|
|
|
@@ -156,18 +143,19 @@ module Backup
|
|
|
156
143
|
# [Generate:Config]
|
|
157
144
|
# Generates the main configuration file
|
|
158
145
|
desc 'generate:config', 'Generates the main Backup bootstrap/configuration file'
|
|
159
|
-
method_option :
|
|
146
|
+
method_option :config_path, :type => :string,
|
|
147
|
+
:desc => 'Path to your Backup configuration directory'
|
|
160
148
|
define_method 'generate:config' do
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
config
|
|
149
|
+
config_path = options[:config_path] ?
|
|
150
|
+
File.expand_path(options[:config_path]) : Config.root_path
|
|
151
|
+
config = File.join(config_path, "config.rb")
|
|
164
152
|
|
|
165
153
|
FileUtils.mkdir_p(config_path)
|
|
166
154
|
if overwrite?(config)
|
|
167
155
|
File.open(config, "w") do |file|
|
|
168
156
|
file.write(Backup::Template.new.result("cli/utility/config"))
|
|
169
157
|
end
|
|
170
|
-
puts "Generated configuration file
|
|
158
|
+
puts "Generated configuration file: '#{ config }'."
|
|
171
159
|
end
|
|
172
160
|
end
|
|
173
161
|
|
|
@@ -192,7 +180,7 @@ module Backup
|
|
|
192
180
|
%x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
|
|
193
181
|
else
|
|
194
182
|
puts "Unknown encryptor: #{options[:encryptor]}"
|
|
195
|
-
puts "Use either 'openssl' or 'gpg'"
|
|
183
|
+
puts "Use either 'openssl' or 'gpg'."
|
|
196
184
|
end
|
|
197
185
|
end
|
|
198
186
|
|
|
@@ -245,55 +233,6 @@ module Backup
|
|
|
245
233
|
|
|
246
234
|
private
|
|
247
235
|
|
|
248
|
-
##
|
|
249
|
-
# Setup required paths based on the given options
|
|
250
|
-
#
|
|
251
|
-
def setup_paths(options)
|
|
252
|
-
##
|
|
253
|
-
# Set PATH if --root-path is given and the directory exists
|
|
254
|
-
root_path = false
|
|
255
|
-
root_given = options[:root_path].strip
|
|
256
|
-
if !root_given.empty? && File.directory?(root_given)
|
|
257
|
-
root_path = File.expand_path(root_given)
|
|
258
|
-
Backup.send(:remove_const, :PATH)
|
|
259
|
-
Backup.send(:const_set, :PATH, root_path)
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
##
|
|
263
|
-
# Update all defaults and given paths to use root_path (if given).
|
|
264
|
-
# Paths given as an absolute path will be used 'as-is'
|
|
265
|
-
{ :config_file => 'config.rb',
|
|
266
|
-
:data_path => 'data',
|
|
267
|
-
:log_path => 'log',
|
|
268
|
-
:cache_path => '.cache',
|
|
269
|
-
:tmp_path => '.tmp' }.each do |key, name|
|
|
270
|
-
# strip any trailing '/' in case the user supplied this as part of
|
|
271
|
-
# an absolute path, so we can match it against File.expand_path()
|
|
272
|
-
given = options[key].sub(/\/\s*$/, '').lstrip
|
|
273
|
-
path = false
|
|
274
|
-
if given.empty?
|
|
275
|
-
path = File.join(root_path, name) if root_path
|
|
276
|
-
else
|
|
277
|
-
path = File.expand_path(given)
|
|
278
|
-
unless given == path
|
|
279
|
-
path = File.join(root_path, given) if root_path
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
const = key.to_s.upcase
|
|
284
|
-
if path
|
|
285
|
-
Backup.send(:remove_const, const)
|
|
286
|
-
Backup.send(:const_set, const, path)
|
|
287
|
-
else
|
|
288
|
-
path = Backup.const_get(const)
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
##
|
|
292
|
-
# Ensure the LOG_PATH, CACHE_PATH and TMP_PATH are created if they do not yet exist
|
|
293
|
-
FileUtils.mkdir_p(path) if [:log_path, :cache_path, :tmp_path].include?(key)
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
236
|
##
|
|
298
237
|
# Helper method for asking the user if he/she wants to overwrite the file
|
|
299
238
|
def overwrite?(path)
|