Parent

Included Modules

Class/Module Index [+]

Quicksearch

Backup::Model

Attributes

archives[R]

The archives attr_accessor holds an array of archive objects

compressor[R]

Holds the configured Compressor

databases[R]

The databases attribute holds an array of database objects

encryptor[R]

Holds the configured Encryptor

label[R]

The label (stored as a String) is used for a more friendly user output

notifiers[R]

The notifiers attr_accessor holds an array of notifier objects

package[R]

The final backup Package this model will create.

splitter[R]

Holds the configured Splitter

storages[R]

The storages attribute holds an array of storage objects

syncers[R]

The syncers attribute holds an array of syncer objects

time[R]

The time when the backup initiated (in format: 2011.02.20.03.29.59)

trigger[R]

The trigger (stored as a String) is used as an identifier for initializing the backup process

Public Class Methods

all() click to toggle source

The Backup::Model.all class method keeps track of all the models that have been instantiated. It returns the @all class variable, which contains an array of all the models

# File lib/backup/model.rb, line 11
def all
  @all ||= []
end
find(trigger) click to toggle source

Return the first model matching trigger. Raises Errors::MissingTriggerError if no matches are found.

# File lib/backup/model.rb, line 18
def find(trigger)
  trigger = trigger.to_s
  all.each do |model|
    return model if model.trigger == trigger
  end
  raise Errors::Model::MissingTriggerError,
      "Could not find trigger '#{trigger}'."
end
find_matching(trigger) click to toggle source

Find and return an Array of all models matching trigger Used to match triggers using a wildcard (*)

# File lib/backup/model.rb, line 30
def find_matching(trigger)
  regex = /^#{ trigger.to_s.gsub('*', '(.*)') }$/
  all.select {|model| regex =~ model.trigger }
end
new(trigger, label, &block) click to toggle source

Takes a trigger, label and the configuration block. After the instance has evaluated the configuration block to configure the model, it will be appended to Model.all

# File lib/backup/model.rb, line 89
def initialize(trigger, label, &block)
  @trigger = trigger.to_s
  @label   = label.to_s

  procedure_instance_variables.each do |variable|
    instance_variable_set(variable, Array.new)
  end

  instance_eval(&block) if block_given?
  Model.all << self
end

Public Instance Methods

archive(name, &block) click to toggle source

Adds an archive to the array of archives to store during the backup process

# File lib/backup/model.rb, line 104
def archive(name, &block)
  @archives << Archive.new(self, name, &block)
end
compress_with(name, &block) click to toggle source

Adds a compressor to use during the backup process

# File lib/backup/model.rb, line 165
def compress_with(name, &block)
  @compressor = get_class_from_scope(Compressor, name).new(&block)
end
database(name, &block) click to toggle source

Adds a database to the array of databases to dump during the backup process

# File lib/backup/model.rb, line 111
def database(name, &block)
  @databases << get_class_from_scope(Database, name).new(self, &block)
end
encrypt_with(name, &block) click to toggle source

Adds an encryptor to use during the backup process

# File lib/backup/model.rb, line 159
def encrypt_with(name, &block)
  @encryptor = get_class_from_scope(Encryptor, name).new(&block)
end
notify_by(name, &block) click to toggle source

Adds a notifier to the array of notifiers to use during the backup process

# File lib/backup/model.rb, line 153
def notify_by(name, &block)
  @notifiers << get_class_from_scope(Notifier, name).new(self, &block)
end
perform!() click to toggle source

Performs the backup process

Databases

Runs all (if any) database objects to dump the databases

Archives

Runs all (if any) archive objects to package all their paths in to a single tar file and places it in the backup folder

Packaging

After all the database dumps and archives are placed inside the folder, it'll make a single .tar package (archive) out of it

Encryption

Optionally encrypts the packaged file with the configured encryptor

Compression

Optionally compresses the each Archive and Database dump with the configured compressor

Splitting

Optionally splits the backup file in to multiple smaller chunks before transferring them

Storages

Runs all (if any) storage objects to store the backups to remote locations and (if configured) it'll cycle the files on the remote location to limit the amount of backups stored on each individual location

Syncers

Runs all (if any) sync objects to store the backups to remote locations. A Syncer does not go through the process of packaging, compressing, encrypting backups. A Syncer directly transfers data from the filesystem to the remote location

Notifiers

Runs all (if any) notifier objects when a backup proces finished with or without any errors.

Cleaning

Once the final Packaging is complete, the temporary folder used will be removed. Then, once all Storages have run, the final packaged files will be removed. If any errors occur during the backup process, all temporary files will be left in place. If the error occurs before Packaging, then the temporary folder (tmp_path/trigger) will remain and may contain all or some of the configured Archives and/or Database dumps. If the error occurs after Packaging, but before the Storages complete, then the final packaged files (located in the root of tmp_path) will remain. *** Important *** If an error occurs and any of the above mentioned temporary files remain, those files *** will be removed *** before the next scheduled backup for the same trigger.

# File lib/backup/model.rb, line 245
def perform!
  @started_at = Time.now
  @time = @started_at.strftime("%Y.%m.%d.%H.%M.%S")
  log!(:started)

  if databases.any? or archives.any?
    procedures.each do |procedure|
      (procedure.call; next) if procedure.is_a?(Proc)
      procedure.each(&:perform!)
    end
  end

  syncers.each(&:perform!)
  notifiers.each(&:perform!)
  log!(:finished)

rescue Exception => err
  fatal = !err.is_a?(StandardError)

  err = Errors::ModelError.wrap(err,         Backup for #{label} (#{trigger}) Failed!        An Error occured which has caused this Backup to abort before completion.)
  Logger.error err
  Logger.error "\nBacktrace:\n\s\s" + err.backtrace.join("\n\s\s") + "\n\n"

  Cleaner.warnings(self)

  if fatal
    Logger.error Errors::ModelError.new(          This Error was Fatal and Backup will now exit.          If you have other Backup jobs (triggers) configured to run,          they will not be processed.)
  else
    Logger.message Errors::ModelError.new(          If you have other Backup jobs (triggers) configured to run,          Backup will now attempt to continue...)
  end

  notifiers.each do |n|
    begin
      n.perform!(true)
    rescue Exception; end
  end

  exit(1) if fatal
end
prepare!() click to toggle source

Ensure DATA_PATH and DATA_PATH/TRIGGER are created if they do not yet exist

Clean any temporary files and/or package files left over from the last time this model/trigger was performed. Logs warnings if files exist and are cleaned.

# File lib/backup/model.rb, line 192
def prepare!
  FileUtils.mkdir_p(File.join(Config.data_path, trigger))
  Cleaner.prepare(self)
end
split_into_chunks_of(chunk_size) click to toggle source

Adds a method that allows the user to configure this backup model to use a Splitter, with the given chunk_size The chunk_size (in megabytes) will later determine in how many chunks the backup needs to be split into

# File lib/backup/model.rb, line 174
def split_into_chunks_of(chunk_size)
  if chunk_size.is_a?(Integer)
    @splitter = Splitter.new(self, chunk_size)
  else
    raise Errors::Model::ConfigurationError,           Invalid Chunk Size for Splitter          Argument to #split_into_chunks_of() must be an Integer
  end
end
store_with(name, storage_id = nil, &block) click to toggle source

Adds a storage method to the array of storage methods to use during the backup process

# File lib/backup/model.rb, line 118
def store_with(name, storage_id = nil, &block)
  @storages << get_class_from_scope(Storage, name).new(self, storage_id, &block)
end
sync_with(name, &block) click to toggle source

Adds a syncer method to the array of syncer methods to use during the backup process

# File lib/backup/model.rb, line 125
def sync_with(name, &block)
  ##
  # Warn user of DSL changes
  case name.to_s
  when 'Backup::Config::RSync'
    Logger.warn Errors::ConfigError.new(          Configuration Update Needed for Syncer::RSync          The RSync Syncer has been split into three separate modules:          RSync::Local, RSync::Push and RSync::Pull          Please update your configuration.          i.e. 'sync_with RSync' is now 'sync_with RSync::Push')
    name = 'RSync::Push'
  when /(Backup::Config::S3|Backup::Config::CloudFiles)/
    syncer = $1.split('::')[2]
    Logger.warn Errors::ConfigError.new(          Configuration Update Needed for '#{ syncer }' Syncer.          This Syncer is now referenced as Cloud::#{ syncer }          i.e. 'sync_with #{ syncer }' is now 'sync_with Cloud::#{ syncer }')
    name = "Cloud::#{ syncer }"
  end
  @syncers << get_class_from_scope(Syncer, name).new(&block)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.