Parent

Included Modules

Class/Module Index [+]

Quicksearch

Backup::Archive

Attributes

excludes[RW]

Stores an array of different paths/files to exclude

name[RW]

Stores the name of the archive

paths[RW]

Stores an array of different paths/files to store

tar_args[RW]

String of additional arguments for the `tar` command

Public Class Methods

new(model, name, &block) click to toggle source

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

Public Instance Methods

add(path) click to toggle source

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
exclude(path) click to toggle source

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
perform!() click to toggle source

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
tar_options(options) click to toggle source

Adds the given String of options to the `tar` command. e.g. '-h --xattrs'

# File lib/backup/archive.rb, line 58
def tar_options(options)
  @tar_args = options
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.