lib/backup/packager.rb in backup-3.0.23 vs lib/backup/packager.rb in backup-3.0.24
- old
+ new
@@ -9,79 +9,89 @@
# Build the final package for the backup model.
def package!(model)
@package = model.package
@encryptor = model.encryptor
@splitter = model.splitter
+ @pipeline = Pipeline.new
Logger.message "Packaging the backup files..."
procedure.call
- Logger.message "Packaging Complete!"
+
+ if @pipeline.success?
+ Logger.message "Packaging Complete!"
+ else
+ raise Errors::Packager::PipelineError,
+ "Failed to Create Backup Package\n" +
+ @pipeline.error_messages
+ end
end
private
##
- # Builds a chain of nested Procs which assemble and execute
- # the final command to package the backup.
+ # Builds a chain of nested Procs which adds each command to a Pipeline
+ # needed to package the final command to package the backup.
# This is done so that the Encryptor and Splitter have the ability
# to perform actions before and after the final command is executed.
# No Encryptors currently utilize this, however the Splitter does.
def procedure
stack = []
##
# Initial `tar` command to package the temporary backup folder.
# The command's output will then be either piped to the Encryptor
- # or the Splitter (if no Encryptor), or redirected into the final
+ # or the Splitter (if no Encryptor), or through `cat` into the final
# output file if neither are configured.
- @package_command = "#{ utility(:tar) } -cf - " +
+ @pipeline << "#{ utility(:tar) } -cf - " +
"-C '#{ Config.tmp_path }' '#{ @package.trigger }'"
##
# If an Encryptor was configured, it will be called first
- # to amend the command to be piped through the encryption utility.
- # It's output will then be either piped into a Splitter, or sent
- # directly to the final output file.
+ # to add the encryption utility command to be piped through,
+ # and amend the final package extension.
+ # It's output will then be either piped into a Splitter,
+ # or through `cat` into the final output file.
if @encryptor
stack << lambda do
@encryptor.encrypt_with do |command, ext|
- @package_command << " | #{command}"
+ @pipeline << command
@package.extension << ext
stack.shift.call
end
end
end
##
- # If a Splitter was configured, the command will be piped through
- # the `split` command. Once the Proc executing the final command
- # has completed and returns back to the Splitter, it will check the
- # final output files to determine if the backup was indeed split.
+ # If a Splitter was configured, the `split` utility command will be
+ # added to the Pipeline to split the final output into multiple files.
+ # Once the Proc executing the Pipeline has completed and returns back
+ # to the Splitter, it will check the final output files to determine
+ # if the backup was indeed split.
# If so, it will set the package's chunk_suffixes. If not, it will
# remove the '-aa' suffix from the only file created by `split`.
#
- # If no Splitter was configured, the command output will be
- # redirected directly into the final output file.
+ # If no Splitter was configured, the final file output will be
+ # piped through `cat` into the final output file.
if @splitter
stack << lambda do
@splitter.split_with do |command|
- @package_command << " | #{command}"
+ @pipeline << command
stack.shift.call
end
end
else
stack << lambda do
outfile = File.join(Config.tmp_path, @package.basename)
- @package_command << " > #{ outfile }"
+ @pipeline << "cat > #{ outfile }"
stack.shift.call
end
end
##
- # Last Proc to be called runs the command the procedure built.
+ # Last Proc to be called runs the Pipeline the procedure built.
# Once complete, the call stack will unwind back through the
# preceeding Procs in the stack (if any)
- stack << lambda { run(@package_command) }
+ stack << lambda { @pipeline.run }
stack.shift
end
end