Object
Exception raised by either a before hook or one of the model’s procedures that caused the model to fail. An exception raised by an after hook would not be stored here. Therefore, it is possible for this to be nil even if exit_status is 2 or 3.
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 12 def all @all ||= [] end
Return an Array of Models matching the given trigger.
# File lib/backup/model.rb, line 18 def find_by_trigger(trigger) trigger = trigger.to_s if trigger.include?('*') regex = /^#{ trigger.gsub('*', '(.*)') }$/ all.select {|model| regex =~ model.trigger } else all.select {|model| trigger == model.trigger } end end
# File lib/backup/model.rb, line 114 def initialize(trigger, label, &block) @trigger = trigger.to_s @label = label.to_s @package = Package.new(self) @databases = [] @archives = [] @storages = [] @notifiers = [] @syncers = [] instance_eval(&self.class.preconfigure) if self.class.preconfigure instance_eval(&block) if block_given? # trigger all defined databases to generate their #dump_filename # so warnings may be logged if `backup perform --check` is used databases.each {|db| db.send(:dump_filename) } Model.all << self end
Defines a block of code to run after the model’s procedures.
This code is ensured to run, even if the model failed, *unless* a before hook raised an exception and aborted the model.
The code block will be passed the model’s current exit_status:
`0`: Success, no warnings. `1`: Success, but warnings were logged. `2`: Failure, but additional models/triggers will still be processed. `3`: Failure, no additional models/triggers will be processed.
The model’s exit_status may be elevated based on the after hook’s actions, but will never be decreased.
Warnings logged within the after hook may elevate the model’s exit_status to 1 and cause warning notifications to be sent.
Raising an exception may elevate the model’s exit_status and cause failure notifications to be sent. If the exception is a StandardError, the exit_status will be elevated to 2. If the exception is not a StandardError, the exit_status will be elevated to 3.
# File lib/backup/model.rb, line 260 def after(&block) @after = block if block @after end
Adds an Archive. Multiple Archives may be added to the model.
# File lib/backup/model.rb, line 137 def archive(name, &block) @archives << Archive.new(self, name, &block) end
Defines a block of code to run before the model’s procedures.
Warnings logged within the before hook will elevate the model’s exit_status to 1 and cause warning notifications to be sent.
Raising an exception will abort the model and cause failure notifications to be sent. If the exception is a StandardError, exit_status will be 2. If the exception is not a StandardError, exit_status will be 3.
If any exception is raised, any defined after hook will be skipped.
# File lib/backup/model.rb, line 232 def before(&block) @before = block if block @before end
Adds an Compressor. Only one Compressor may be added to the model. This will be used to compress each individual Archive and Database stored within the final backup package.
# File lib/backup/model.rb, line 199 def compress_with(name, &block) @compressor = get_class_from_scope(Compressor, name).new(&block) end
Adds an Database. Multiple Databases may be added to the model.
# File lib/backup/model.rb, line 143 def database(name, database_id = nil, &block) @databases << get_class_from_scope(Database, name). new(self, database_id, &block) end
The duration of the backup process (in format: HH:MM:SS)
# File lib/backup/model.rb, line 312 def duration return unless finished_at elapsed_time(started_at, finished_at) end
Adds an Notifier. Multiple Notifiers may be added to the model.
# File lib/backup/model.rb, line 184 def notify_by(name, &block) @notifiers << get_class_from_scope(Notifier, name).new(self, &block) end
Performs the backup process
Once complete, exit_status will indicate the result of this process.
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 281 def perform! @started_at = Time.now.utc @time = package.time = started_at.strftime("%Y.%m.%d.%H.%M.%S") log!(:started) before_hook procedures.each do |procedure| procedure.is_a?(Proc) ? procedure.call : procedure.each(&:perform!) end syncers.each(&:perform!) rescue Interrupt @interrupted = true raise rescue Exception => err @exception = err ensure unless @interrupted set_exit_status @finished_at = Time.now.utc log!(:finished) after_hook end end
Adds a Splitter to split the final backup package into multiple files.
chunk_size is specified in MiB and must be given as an Integer. suffix_length controls the number of characters used in the suffix (and the maximum number of chunks possible). ie. 1 (-a, -b), 2 (-aa, -ab), 3 (-aaa, -aab)
# File lib/backup/model.rb, line 210 def split_into_chunks_of(chunk_size, suffix_length = 2) if chunk_size.is_a?(Integer) && suffix_length.is_a?(Integer) @splitter = Splitter.new(self, chunk_size, suffix_length) else raise Error, Invalid arguments for #split_into_chunks_of() +chunk_size+ (and optional +suffix_length+) must be Integers. end end
Adds an Storage. Multiple Storages may be added to the model.
# File lib/backup/model.rb, line 150 def store_with(name, storage_id = nil, &block) @storages << get_class_from_scope(Storage, name). new(self, storage_id, &block) end
Adds an Syncer. Multiple Syncers may be added to the model.
# File lib/backup/model.rb, line 157 def sync_with(name, syncer_id = nil, &block) ## # Warn user of DSL changes case name.to_s when 'Backup::Config::RSync' Logger.warn Error.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 Error.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(syncer_id, &block) end
Generated with the Darkfish Rdoc Generator 2.