backup 3.0.27 → 3.1.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/LICENSE.md +1 -1
- data/README.md +139 -386
- data/bin/backup +1 -7
- data/lib/backup.rb +3 -9
- data/lib/backup/archive.rb +26 -20
- data/lib/backup/cleaner.rb +2 -2
- data/lib/backup/cli.rb +366 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/gzip.rb +35 -1
- data/lib/backup/config.rb +1 -2
- data/lib/backup/database/base.rb +2 -2
- data/lib/backup/database/mongodb.rb +3 -3
- data/lib/backup/database/mysql.rb +3 -2
- data/lib/backup/database/postgresql.rb +3 -2
- data/lib/backup/database/riak.rb +18 -5
- data/lib/backup/dependency.rb +144 -93
- data/lib/backup/encryptor/base.rb +2 -2
- data/lib/backup/logger.rb +108 -110
- data/lib/backup/logger/console.rb +51 -0
- data/lib/backup/logger/logfile.rb +113 -0
- data/lib/backup/logger/syslog.rb +116 -0
- data/lib/backup/model.rb +67 -65
- data/lib/backup/notifier/base.rb +1 -1
- data/lib/backup/notifier/hipchat.rb +1 -1
- data/lib/backup/notifier/mail.rb +1 -1
- data/lib/backup/notifier/pushover.rb +6 -3
- data/lib/backup/packager.rb +4 -4
- data/lib/backup/pipeline.rb +17 -3
- data/lib/backup/splitter.rb +2 -2
- data/lib/backup/storage/base.rb +2 -2
- data/lib/backup/storage/cloudfiles.rb +2 -2
- data/lib/backup/storage/dropbox.rb +4 -4
- data/lib/backup/storage/ftp.rb +2 -2
- data/lib/backup/storage/local.rb +2 -2
- data/lib/backup/storage/ninefold.rb +2 -2
- data/lib/backup/storage/rsync.rb +3 -3
- data/lib/backup/storage/s3.rb +2 -2
- data/lib/backup/storage/scp.rb +2 -6
- data/lib/backup/storage/sftp.rb +2 -5
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/cloud/base.rb +15 -8
- data/lib/backup/syncer/rsync/local.rb +1 -1
- data/lib/backup/syncer/rsync/pull.rb +1 -1
- data/lib/backup/syncer/rsync/push.rb +1 -1
- data/lib/backup/utilities.rb +211 -0
- data/lib/backup/version.rb +1 -1
- data/templates/cli/{utility/archive → archive} +4 -8
- data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
- data/templates/cli/{utility/compressor → compressor}/custom +0 -0
- data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
- data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
- data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
- data/templates/cli/config +68 -0
- data/templates/cli/{utility/database → database}/mongodb +1 -1
- data/templates/cli/{utility/database → database}/mysql +1 -1
- data/templates/cli/{utility/database → database}/postgresql +1 -1
- data/templates/cli/{utility/database → database}/redis +0 -0
- data/templates/cli/database/riak +20 -0
- data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
- data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
- data/templates/cli/{utility/model.erb → model.erb} +4 -4
- data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
- data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
- data/templates/cli/{utility/notifier → notifier}/mail +0 -0
- data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
- data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
- data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
- data/templates/cli/{utility/splitter → splitter} +0 -0
- data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
- data/templates/cli/{utility/storage → storage}/dropbox +0 -0
- data/templates/cli/{utility/storage → storage}/ftp +0 -0
- data/templates/cli/{utility/storage → storage}/local +0 -0
- data/templates/cli/{utility/storage → storage}/ninefold +0 -0
- data/templates/cli/{utility/storage → storage}/rsync +0 -0
- data/templates/cli/{utility/storage → storage}/s3 +0 -0
- data/templates/cli/{utility/storage → storage}/scp +0 -0
- data/templates/cli/{utility/storage → storage}/sftp +0 -0
- data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
- data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
- metadata +55 -131
- data/.gitignore +0 -8
- data/.travis.yml +0 -10
- data/Gemfile +0 -28
- data/Guardfile +0 -23
- data/backup.gemspec +0 -32
- data/lib/backup/cli/helpers.rb +0 -93
- data/lib/backup/cli/utility.rb +0 -255
- data/spec-live/.gitignore +0 -6
- data/spec-live/README +0 -7
- data/spec-live/backups/config.rb +0 -83
- data/spec-live/backups/config.yml.template +0 -46
- data/spec-live/backups/models.rb +0 -184
- data/spec-live/compressor/custom_spec.rb +0 -30
- data/spec-live/compressor/gzip_spec.rb +0 -30
- data/spec-live/encryptor/gpg_keys.rb +0 -239
- data/spec-live/encryptor/gpg_spec.rb +0 -287
- data/spec-live/notifier/mail_spec.rb +0 -121
- data/spec-live/spec_helper.rb +0 -151
- data/spec-live/storage/dropbox_spec.rb +0 -151
- data/spec-live/storage/local_spec.rb +0 -83
- data/spec-live/storage/scp_spec.rb +0 -193
- data/spec-live/syncer/cloud/s3_spec.rb +0 -124
- data/spec/archive_spec.rb +0 -335
- data/spec/cleaner_spec.rb +0 -312
- data/spec/cli/helpers_spec.rb +0 -301
- data/spec/cli/utility_spec.rb +0 -411
- data/spec/compressor/base_spec.rb +0 -52
- data/spec/compressor/bzip2_spec.rb +0 -217
- data/spec/compressor/custom_spec.rb +0 -106
- data/spec/compressor/gzip_spec.rb +0 -217
- data/spec/compressor/lzma_spec.rb +0 -123
- data/spec/compressor/pbzip2_spec.rb +0 -165
- data/spec/config_spec.rb +0 -321
- data/spec/configuration/helpers_spec.rb +0 -247
- data/spec/configuration/store_spec.rb +0 -39
- data/spec/configuration_spec.rb +0 -62
- data/spec/database/base_spec.rb +0 -63
- data/spec/database/mongodb_spec.rb +0 -510
- data/spec/database/mysql_spec.rb +0 -411
- data/spec/database/postgresql_spec.rb +0 -353
- data/spec/database/redis_spec.rb +0 -334
- data/spec/database/riak_spec.rb +0 -176
- data/spec/dependency_spec.rb +0 -51
- data/spec/encryptor/base_spec.rb +0 -40
- data/spec/encryptor/gpg_spec.rb +0 -909
- data/spec/encryptor/open_ssl_spec.rb +0 -148
- data/spec/errors_spec.rb +0 -306
- data/spec/logger_spec.rb +0 -367
- data/spec/model_spec.rb +0 -666
- data/spec/notifier/base_spec.rb +0 -104
- data/spec/notifier/campfire_spec.rb +0 -217
- data/spec/notifier/hipchat_spec.rb +0 -211
- data/spec/notifier/mail_spec.rb +0 -316
- data/spec/notifier/prowl_spec.rb +0 -138
- data/spec/notifier/pushover_spec.rb +0 -123
- data/spec/notifier/twitter_spec.rb +0 -153
- data/spec/package_spec.rb +0 -61
- data/spec/packager_spec.rb +0 -213
- data/spec/pipeline_spec.rb +0 -259
- data/spec/spec_helper.rb +0 -60
- data/spec/splitter_spec.rb +0 -120
- data/spec/storage/base_spec.rb +0 -166
- data/spec/storage/cloudfiles_spec.rb +0 -254
- data/spec/storage/cycler_spec.rb +0 -247
- data/spec/storage/dropbox_spec.rb +0 -480
- data/spec/storage/ftp_spec.rb +0 -271
- data/spec/storage/local_spec.rb +0 -259
- data/spec/storage/ninefold_spec.rb +0 -343
- data/spec/storage/rsync_spec.rb +0 -362
- data/spec/storage/s3_spec.rb +0 -245
- data/spec/storage/scp_spec.rb +0 -233
- data/spec/storage/sftp_spec.rb +0 -244
- data/spec/syncer/base_spec.rb +0 -109
- data/spec/syncer/cloud/base_spec.rb +0 -515
- data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
- data/spec/syncer/cloud/s3_spec.rb +0 -174
- data/spec/syncer/rsync/base_spec.rb +0 -98
- data/spec/syncer/rsync/local_spec.rb +0 -149
- data/spec/syncer/rsync/pull_spec.rb +0 -98
- data/spec/syncer/rsync/push_spec.rb +0 -333
- data/spec/version_spec.rb +0 -21
- data/templates/cli/utility/config +0 -32
- data/templates/cli/utility/database/riak +0 -11
data/lib/backup/model.rb
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
module Backup
|
|
4
4
|
class Model
|
|
5
|
-
include Backup::CLI::Helpers
|
|
6
|
-
|
|
7
5
|
class << self
|
|
8
6
|
##
|
|
9
7
|
# The Backup::Model.all class method keeps track of all the models
|
|
@@ -14,23 +12,14 @@ module Backup
|
|
|
14
12
|
end
|
|
15
13
|
|
|
16
14
|
##
|
|
17
|
-
# Return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
# Return an Array of Models matching the given +trigger+.
|
|
16
|
+
def find_by_trigger(trigger)
|
|
17
|
+
if trigger.include?('*')
|
|
18
|
+
regex = /^#{ trigger.to_s.gsub('*', '(.*)') }$/
|
|
19
|
+
all.select {|model| regex =~ model.trigger }
|
|
20
|
+
else
|
|
21
|
+
all.select {|model| trigger == model.trigger }
|
|
23
22
|
end
|
|
24
|
-
raise Errors::Model::MissingTriggerError,
|
|
25
|
-
"Could not find trigger '#{trigger}'."
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
##
|
|
29
|
-
# Find and return an Array of all models matching +trigger+
|
|
30
|
-
# Used to match triggers using a wildcard (*)
|
|
31
|
-
def find_matching(trigger)
|
|
32
|
-
regex = /^#{ trigger.to_s.gsub('*', '(.*)') }$/
|
|
33
|
-
all.select {|model| regex =~ model.trigger }
|
|
34
23
|
end
|
|
35
24
|
end
|
|
36
25
|
|
|
@@ -183,18 +172,6 @@ module Backup
|
|
|
183
172
|
end
|
|
184
173
|
end
|
|
185
174
|
|
|
186
|
-
##
|
|
187
|
-
# Ensure DATA_PATH and DATA_PATH/TRIGGER are created
|
|
188
|
-
# if they do not yet exist
|
|
189
|
-
#
|
|
190
|
-
# Clean any temporary files and/or package files left over
|
|
191
|
-
# from the last time this model/trigger was performed.
|
|
192
|
-
# Logs warnings if files exist and are cleaned.
|
|
193
|
-
def prepare!
|
|
194
|
-
FileUtils.mkdir_p(File.join(Config.data_path, trigger))
|
|
195
|
-
Cleaner.prepare(self)
|
|
196
|
-
end
|
|
197
|
-
|
|
198
175
|
##
|
|
199
176
|
# Performs the backup process
|
|
200
177
|
##
|
|
@@ -248,6 +225,8 @@ module Backup
|
|
|
248
225
|
@time = @started_at.strftime("%Y.%m.%d.%H.%M.%S")
|
|
249
226
|
log!(:started)
|
|
250
227
|
|
|
228
|
+
prepare!
|
|
229
|
+
|
|
251
230
|
if databases.any? or archives.any?
|
|
252
231
|
procedures.each do |procedure|
|
|
253
232
|
(procedure.call; next) if procedure.is_a?(Proc)
|
|
@@ -260,41 +239,25 @@ module Backup
|
|
|
260
239
|
log!(:finished)
|
|
261
240
|
|
|
262
241
|
rescue Exception => err
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
Backup for #{label} (#{trigger}) Failed!
|
|
267
|
-
An Error occured which has caused this Backup to abort before completion.
|
|
268
|
-
EOS
|
|
269
|
-
Logger.error err
|
|
270
|
-
Logger.error "\nBacktrace:\n\s\s" + err.backtrace.join("\n\s\s") + "\n\n"
|
|
271
|
-
|
|
272
|
-
Cleaner.warnings(self)
|
|
273
|
-
|
|
274
|
-
if fatal
|
|
275
|
-
Logger.error Errors::ModelError.new(<<-EOS)
|
|
276
|
-
This Error was Fatal and Backup will now exit.
|
|
277
|
-
If you have other Backup jobs (triggers) configured to run,
|
|
278
|
-
they will not be processed.
|
|
279
|
-
EOS
|
|
280
|
-
else
|
|
281
|
-
Logger.message Errors::ModelError.new(<<-EOS)
|
|
282
|
-
If you have other Backup jobs (triggers) configured to run,
|
|
283
|
-
Backup will now attempt to continue...
|
|
284
|
-
EOS
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
notifiers.each do |n|
|
|
288
|
-
begin
|
|
289
|
-
n.perform!(true)
|
|
290
|
-
rescue Exception; end
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
exit(1) if fatal
|
|
242
|
+
log!(:failure, err)
|
|
243
|
+
send_failure_notifications
|
|
244
|
+
exit(1) unless err.is_a?(StandardError)
|
|
294
245
|
end
|
|
295
246
|
|
|
296
247
|
private
|
|
297
248
|
|
|
249
|
+
##
|
|
250
|
+
# Ensure DATA_PATH and DATA_PATH/TRIGGER are created
|
|
251
|
+
# if they do not yet exist
|
|
252
|
+
#
|
|
253
|
+
# Clean any temporary files and/or package files left over
|
|
254
|
+
# from the last time this model/trigger was performed.
|
|
255
|
+
# Logs warnings if files exist and are cleaned.
|
|
256
|
+
def prepare!
|
|
257
|
+
FileUtils.mkdir_p(File.join(Config.data_path, trigger))
|
|
258
|
+
Cleaner.prepare(self)
|
|
259
|
+
end
|
|
260
|
+
|
|
298
261
|
##
|
|
299
262
|
# After all the databases and archives have been dumped and sorted,
|
|
300
263
|
# these files will be bundled in to a .tar archive (uncompressed),
|
|
@@ -352,11 +315,11 @@ module Backup
|
|
|
352
315
|
end
|
|
353
316
|
|
|
354
317
|
##
|
|
355
|
-
# Logs messages when the backup starts
|
|
356
|
-
def log!(action)
|
|
318
|
+
# Logs messages when the backup starts, finishes or fails
|
|
319
|
+
def log!(action, exception = nil)
|
|
357
320
|
case action
|
|
358
321
|
when :started
|
|
359
|
-
Logger.
|
|
322
|
+
Logger.info "Performing Backup for '#{label} (#{trigger})'!\n" +
|
|
360
323
|
"[ backup #{ Version.current } : #{ RUBY_DESCRIPTION } ]"
|
|
361
324
|
|
|
362
325
|
when :finished
|
|
@@ -365,7 +328,30 @@ module Backup
|
|
|
365
328
|
if Logger.has_warnings?
|
|
366
329
|
Logger.warn msg % 'Successfully (with Warnings)'
|
|
367
330
|
else
|
|
368
|
-
Logger.
|
|
331
|
+
Logger.info msg % 'Successfully'
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
when :failure
|
|
335
|
+
err = Errors::ModelError.wrap(exception, <<-EOS)
|
|
336
|
+
Backup for #{label} (#{trigger}) Failed!
|
|
337
|
+
An Error occured which has caused this Backup to abort before completion.
|
|
338
|
+
EOS
|
|
339
|
+
Logger.error err
|
|
340
|
+
Logger.error "\nBacktrace:\n\s\s" + err.backtrace.join("\n\s\s") + "\n\n"
|
|
341
|
+
|
|
342
|
+
Cleaner.warnings(self)
|
|
343
|
+
|
|
344
|
+
if exception.is_a?(StandardError)
|
|
345
|
+
Logger.info Errors::ModelError.new(<<-EOS)
|
|
346
|
+
If you have other Backup jobs (triggers) configured to run,
|
|
347
|
+
Backup will now attempt to continue...
|
|
348
|
+
EOS
|
|
349
|
+
else
|
|
350
|
+
Logger.error Errors::ModelError.new(<<-EOS)
|
|
351
|
+
This Error was Fatal and Backup will now exit.
|
|
352
|
+
If you have other Backup jobs (triggers) configured to run,
|
|
353
|
+
they will not be processed.
|
|
354
|
+
EOS
|
|
369
355
|
end
|
|
370
356
|
end
|
|
371
357
|
end
|
|
@@ -381,5 +367,21 @@ module Backup
|
|
|
381
367
|
'%02d:%02d:%02d' % [hours, minutes, seconds]
|
|
382
368
|
end
|
|
383
369
|
|
|
370
|
+
##
|
|
371
|
+
# Sends notifications when a backup fails.
|
|
372
|
+
# Errors are logged and rescued, since the error that caused the
|
|
373
|
+
# backup to fail could have been an error with a notifier.
|
|
374
|
+
def send_failure_notifications
|
|
375
|
+
notifiers.each do |n|
|
|
376
|
+
begin
|
|
377
|
+
n.perform!(true)
|
|
378
|
+
rescue Exception => err
|
|
379
|
+
Logger.error Errors::ModelError.wrap(err, <<-EOS)
|
|
380
|
+
#{ n.class } Failed to send notification of backup failure.
|
|
381
|
+
EOS
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
|
|
384
386
|
end
|
|
385
387
|
end
|
data/lib/backup/notifier/base.rb
CHANGED
|
@@ -73,7 +73,7 @@ module Backup
|
|
|
73
73
|
# Logs a message to the console and log file to inform
|
|
74
74
|
# the client that Backup is notifying about the process
|
|
75
75
|
def log!
|
|
76
|
-
Logger.
|
|
76
|
+
Logger.info "#{ notifier_name } started notifying about the process."
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
end
|
|
@@ -83,7 +83,7 @@ module Backup
|
|
|
83
83
|
|
|
84
84
|
def send_message(msg, color)
|
|
85
85
|
client = HipChat::Client.new(token)
|
|
86
|
-
|
|
86
|
+
Array(rooms_notified).map {|r| r.split(',').map(&:strip) }.flatten.each do |room|
|
|
87
87
|
client[room].send(from, msg, :color => color, :notify => notify_users)
|
|
88
88
|
end
|
|
89
89
|
end
|
data/lib/backup/notifier/mail.rb
CHANGED
|
@@ -150,7 +150,7 @@ module Backup
|
|
|
150
150
|
email.convert_to_multipart
|
|
151
151
|
email.attachments["#{@model.time}.#{@model.trigger}.log"] = {
|
|
152
152
|
:mime_type => 'text/plain;',
|
|
153
|
-
:content => Logger.messages.join("\n")
|
|
153
|
+
:content => Logger.messages.map(&:formatted_lines).flatten.join("\n")
|
|
154
154
|
}
|
|
155
155
|
end
|
|
156
156
|
|
|
@@ -14,7 +14,8 @@ module Backup
|
|
|
14
14
|
attr_accessor :token
|
|
15
15
|
|
|
16
16
|
##
|
|
17
|
-
# The user's device identifier to sent
|
|
17
|
+
# The user's device identifier to sent the message directly to,
|
|
18
|
+
# rather than all of the user's devices
|
|
18
19
|
attr_accessor :device
|
|
19
20
|
|
|
20
21
|
##
|
|
@@ -68,7 +69,7 @@ module Backup
|
|
|
68
69
|
url = URI.parse("https://api.pushover.net/1/messages.json")
|
|
69
70
|
|
|
70
71
|
request = Net::HTTP::Post.new(url.path)
|
|
71
|
-
request.set_form_data(parameters.merge
|
|
72
|
+
request.set_form_data(parameters.merge({:message => message}))
|
|
72
73
|
response = Net::HTTP.new(url.host, url.port)
|
|
73
74
|
|
|
74
75
|
response.use_ssl = true
|
|
@@ -80,7 +81,9 @@ module Backup
|
|
|
80
81
|
# List available parameters
|
|
81
82
|
def parameters
|
|
82
83
|
@values = {}
|
|
83
|
-
[:token, :user, :message, :title, :priority, :device].each
|
|
84
|
+
[:token, :user, :message, :title, :priority, :device].each do |k|
|
|
85
|
+
@values.merge! k => self.instance_variable_get("@#{k}")
|
|
86
|
+
end
|
|
84
87
|
@values
|
|
85
88
|
end
|
|
86
89
|
end
|
data/lib/backup/packager.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Backup
|
|
4
4
|
module Packager
|
|
5
5
|
class << self
|
|
6
|
-
include Backup::
|
|
6
|
+
include Backup::Utilities::Helpers
|
|
7
7
|
|
|
8
8
|
##
|
|
9
9
|
# Build the final package for the backup model.
|
|
@@ -13,11 +13,11 @@ module Backup
|
|
|
13
13
|
@splitter = model.splitter
|
|
14
14
|
@pipeline = Pipeline.new
|
|
15
15
|
|
|
16
|
-
Logger.
|
|
16
|
+
Logger.info "Packaging the backup files..."
|
|
17
17
|
procedure.call
|
|
18
18
|
|
|
19
19
|
if @pipeline.success?
|
|
20
|
-
Logger.
|
|
20
|
+
Logger.info "Packaging Complete!"
|
|
21
21
|
else
|
|
22
22
|
raise Errors::Packager::PipelineError,
|
|
23
23
|
"Failed to Create Backup Package\n" +
|
|
@@ -81,7 +81,7 @@ module Backup
|
|
|
81
81
|
else
|
|
82
82
|
stack << lambda do
|
|
83
83
|
outfile = File.join(Config.tmp_path, @package.basename)
|
|
84
|
-
@pipeline << "cat > #{ outfile }"
|
|
84
|
+
@pipeline << "#{ utility(:cat) } > #{ outfile }"
|
|
85
85
|
stack.shift.call
|
|
86
86
|
end
|
|
87
87
|
end
|
data/lib/backup/pipeline.rb
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
module Backup
|
|
4
4
|
class Pipeline
|
|
5
|
-
include Backup::
|
|
5
|
+
include Backup::Utilities::Helpers
|
|
6
6
|
|
|
7
7
|
attr_reader :stderr, :errors
|
|
8
8
|
|
|
9
9
|
def initialize
|
|
10
10
|
@commands = []
|
|
11
|
+
@success_codes = []
|
|
11
12
|
@errors = []
|
|
12
13
|
@stderr = ''
|
|
13
14
|
end
|
|
@@ -16,8 +17,21 @@ module Backup
|
|
|
16
17
|
# Adds a command to be executed in the pipeline.
|
|
17
18
|
# Each command will be run in the order in which it was added,
|
|
18
19
|
# with it's output being piped to the next command.
|
|
19
|
-
|
|
20
|
+
#
|
|
21
|
+
# +success_codes+ must be an Array of Integer exit codes that will
|
|
22
|
+
# be considered successful for the +command+.
|
|
23
|
+
def add(command, success_codes)
|
|
20
24
|
@commands << command
|
|
25
|
+
@success_codes << success_codes
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# Commands added using this method will only be considered successful
|
|
30
|
+
# if their exit status is 0.
|
|
31
|
+
#
|
|
32
|
+
# Use #add if successful exit status codes need to be specified.
|
|
33
|
+
def <<(command)
|
|
34
|
+
add(command, [0])
|
|
21
35
|
end
|
|
22
36
|
|
|
23
37
|
##
|
|
@@ -39,7 +53,7 @@ module Backup
|
|
|
39
53
|
pipestatus = stdout.read.gsub("\n", '').split(':').sort
|
|
40
54
|
pipestatus.each do |status|
|
|
41
55
|
index, exitstatus = status.split('|').map(&:to_i)
|
|
42
|
-
|
|
56
|
+
unless @success_codes[index].include?(exitstatus)
|
|
43
57
|
command = command_name(@commands[index])
|
|
44
58
|
@errors << SystemCallError.new(
|
|
45
59
|
"'#{ command }' returned exit code: #{ exitstatus }", exitstatus
|
data/lib/backup/splitter.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Backup
|
|
4
4
|
class Splitter
|
|
5
|
-
include Backup::
|
|
5
|
+
include Backup::Utilities::Helpers
|
|
6
6
|
|
|
7
7
|
def initialize(model, chunk_size)
|
|
8
8
|
@model = model
|
|
@@ -32,7 +32,7 @@ module Backup
|
|
|
32
32
|
# be suffixed using 'aa', 'ab', and so on... for each file.
|
|
33
33
|
def before_packaging
|
|
34
34
|
@package = @model.package
|
|
35
|
-
Logger.
|
|
35
|
+
Logger.info "Splitter configured with a chunk size of " +
|
|
36
36
|
"#{ @chunk_size }MB."
|
|
37
37
|
|
|
38
38
|
@split_command = "#{ utility(:split) } -b #{ @chunk_size }m - " +
|
data/lib/backup/storage/base.rb
CHANGED
|
@@ -89,9 +89,9 @@ module Backup
|
|
|
89
89
|
# containing the original error message.
|
|
90
90
|
def cycle!
|
|
91
91
|
return unless keep.to_i > 0
|
|
92
|
-
Logger.
|
|
92
|
+
Logger.info "#{ storage_name }: Cycling Started..."
|
|
93
93
|
Cycler.cycle!(self, @package)
|
|
94
|
-
Logger.
|
|
94
|
+
Logger.info "#{ storage_name }: Cycling Complete!"
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
end
|
|
@@ -58,7 +58,7 @@ module Backup
|
|
|
58
58
|
remote_path = remote_path_for(@package)
|
|
59
59
|
|
|
60
60
|
files_to_transfer_for(@package) do |local_file, remote_file|
|
|
61
|
-
Logger.
|
|
61
|
+
Logger.info "#{storage_name} started transferring '#{ local_file }'."
|
|
62
62
|
|
|
63
63
|
File.open(File.join(local_path, local_file), 'r') do |file|
|
|
64
64
|
connection.put_object(
|
|
@@ -76,7 +76,7 @@ module Backup
|
|
|
76
76
|
remote_path = remote_path_for(package)
|
|
77
77
|
|
|
78
78
|
transferred_files_for(package) do |local_file, remote_file|
|
|
79
|
-
Logger.
|
|
79
|
+
Logger.info "#{storage_name} started removing '#{ local_file }' " +
|
|
80
80
|
"from container '#{ container }'."
|
|
81
81
|
connection.delete_object(container, File.join(remote_path, remote_file))
|
|
82
82
|
end
|
|
@@ -55,7 +55,7 @@ module Backup
|
|
|
55
55
|
return @connection if @connection
|
|
56
56
|
|
|
57
57
|
unless session = cached_session
|
|
58
|
-
Logger.
|
|
58
|
+
Logger.info "Creating a new session!"
|
|
59
59
|
session = create_write_and_return_new_session!
|
|
60
60
|
end
|
|
61
61
|
|
|
@@ -73,7 +73,7 @@ module Backup
|
|
|
73
73
|
if cache_exists?
|
|
74
74
|
begin
|
|
75
75
|
session = DropboxSession.deserialize(File.read(cached_file))
|
|
76
|
-
Logger.
|
|
76
|
+
Logger.info "Session data loaded from cache!"
|
|
77
77
|
|
|
78
78
|
rescue => err
|
|
79
79
|
Logger.warn Errors::Storage::Dropbox::CacheError.wrap(err, <<-EOS)
|
|
@@ -91,7 +91,7 @@ module Backup
|
|
|
91
91
|
remote_path = remote_path_for(@package)
|
|
92
92
|
|
|
93
93
|
files_to_transfer_for(@package) do |local_file, remote_file|
|
|
94
|
-
Logger.
|
|
94
|
+
Logger.info "#{storage_name} started transferring '#{ local_file }'."
|
|
95
95
|
File.open(File.join(local_path, local_file), 'r') do |file|
|
|
96
96
|
connection.put_file(File.join(remote_path, remote_file), file)
|
|
97
97
|
end
|
|
@@ -110,7 +110,7 @@ module Backup
|
|
|
110
110
|
messages << "#{storage_name} started removing " +
|
|
111
111
|
"'#{ local_file }' from Dropbox."
|
|
112
112
|
end
|
|
113
|
-
Logger.
|
|
113
|
+
Logger.info messages.join("\n")
|
|
114
114
|
|
|
115
115
|
connection.file_delete(remote_path)
|
|
116
116
|
end
|
data/lib/backup/storage/ftp.rb
CHANGED
|
@@ -67,7 +67,7 @@ module Backup
|
|
|
67
67
|
create_remote_path(remote_path, ftp)
|
|
68
68
|
|
|
69
69
|
files_to_transfer_for(@package) do |local_file, remote_file|
|
|
70
|
-
Logger.
|
|
70
|
+
Logger.info "#{storage_name} started transferring " +
|
|
71
71
|
"'#{ local_file }' to '#{ ip }'."
|
|
72
72
|
ftp.put(
|
|
73
73
|
File.join(local_path, local_file),
|
|
@@ -86,7 +86,7 @@ module Backup
|
|
|
86
86
|
|
|
87
87
|
connection do |ftp|
|
|
88
88
|
transferred_files_for(package) do |local_file, remote_file|
|
|
89
|
-
Logger.
|
|
89
|
+
Logger.info "#{storage_name} started removing " +
|
|
90
90
|
"'#{ local_file }' from '#{ ip }'."
|
|
91
91
|
|
|
92
92
|
ftp.delete(File.join(remote_path, remote_file))
|
data/lib/backup/storage/local.rb
CHANGED
|
@@ -32,7 +32,7 @@ module Backup
|
|
|
32
32
|
FileUtils.mkdir_p(remote_path)
|
|
33
33
|
|
|
34
34
|
files_to_transfer_for(@package) do |local_file, remote_file|
|
|
35
|
-
Logger.
|
|
35
|
+
Logger.info "#{storage_name} started transferring '#{ local_file }'."
|
|
36
36
|
|
|
37
37
|
src_path = File.join(local_path, local_file)
|
|
38
38
|
dst_path = File.join(remote_path, remote_file)
|
|
@@ -51,7 +51,7 @@ module Backup
|
|
|
51
51
|
transferred_files_for(package) do |local_file, remote_file|
|
|
52
52
|
messages << "#{storage_name} started removing '#{ local_file }'."
|
|
53
53
|
end
|
|
54
|
-
Logger.
|
|
54
|
+
Logger.info messages.join("\n")
|
|
55
55
|
|
|
56
56
|
FileUtils.rm_r(remote_path)
|
|
57
57
|
end
|