Object
Takes the name of the archive and the configuration block
# File lib/backup/archive.rb, line 24 def initialize(model, name, &block) @model = model @name = name.to_s @paths = Array.new @excludes = Array.new @tar_args = '' instance_eval(&block) if block_given? end
Adds new paths to the @paths instance variable array
# File lib/backup/archive.rb, line 36 def add(path) path = File.expand_path(path) if File.exist?(path) @paths << path else Logger.warn Errors::Archive::NotFoundError.new( The following path was not found: #{ path } This path will be omitted from the '#{ name }' Archive.) end end
Adds new paths to the @excludes instance variable array
# File lib/backup/archive.rb, line 51 def exclude(path) @excludes << File.expand_path(path) end
Archives all the provided paths in to a single .tar file and places that .tar file in the folder which later will be packaged If the model is configured with a Compressor, the tar command output will be piped through the Compressor command and the file extension will be adjusted to indicate the type of compression used.
# File lib/backup/archive.rb, line 68 def perform! Logger.message "#{ self.class } has started archiving:\n" + paths.map {|path| " #{path}" }.join("\n") archive_path = File.join(Config.tmp_path, @model.trigger, 'archives') FileUtils.mkdir_p(archive_path) archive_ext = 'tar' pipeline = Pipeline.new pipeline << "#{ utility(:tar) } #{ tar_args } -cPf - " + "#{ paths_to_exclude } #{ paths_to_package }" if @model.compressor @model.compressor.compress_with do |command, ext| pipeline << command archive_ext << ext end end pipeline << "cat > '#{ File.join(archive_path, "#{name}.#{archive_ext}") }'" pipeline.run if pipeline.success? Logger.message "#{ self.class } Complete!" else raise Errors::Archive::PipelineError, "Failed to Create Backup Archive\n" + pipeline.error_messages end end
Generated with the Darkfish Rdoc Generator 2.