Class: Backup::Model
Class Attribute Summary collapse
-
.all ⇒ Object
The Backup::Model.all class method keeps track of all the models that have been instantiated.
-
.current ⇒ Object
Contains the currently-in-use model.
-
.extension ⇒ Object
Contains the current file extension (this changes from time to time after a file gets compressed or encrypted so we can keep track of the correct file when new extensions get appended to the current file name).
Instance Attribute Summary collapse
-
#archives ⇒ Object
The archives attr_accessor holds an array of archive objects.
-
#compressors ⇒ Object
The compressors attr_accessor holds an array of compressor objects.
-
#databases ⇒ Object
The databases attribute holds an array of database objects.
-
#encryptors ⇒ Object
The encryptors attr_accessor holds an array of encryptor objects.
-
#label ⇒ Object
The label is used for a more friendly user output.
-
#notifiers ⇒ Object
The notifiers attr_accessor holds an array of notifier objects.
-
#storages ⇒ Object
The storages attribute holds an array of storage objects.
-
#syncers ⇒ Object
The syncers attribute holds an array of syncer objects.
-
#time ⇒ Object
The time when the backup initiated (in format: 2011.02.20.03.29.59).
-
#trigger ⇒ Object
The trigger is used as an identifier for initializing the backup process.
Class Method Summary collapse
-
.file ⇒ Object
Returns the full path to the current file (including the current extension).
-
.tmp_path ⇒ Object
Returns the temporary trigger path of the current model e.g.
Instance Method Summary collapse
-
#archive(name, &block) ⇒ Object
Adds an archive to the array of archives to store during the backup process.
-
#compress_with(name, &block) ⇒ Object
Adds a compressor to the array of compressors to use during the backup process.
-
#database(database, &block) ⇒ Object
Adds a database to the array of databases to dump during the backup process.
-
#encrypt_with(name, &block) ⇒ Object
Adds an encryptor to the array of encryptors to use during the backup process.
-
#initialize(trigger, label, &block) ⇒ Model
constructor
Takes a trigger, label and the configuration block and instantiates the model.
-
#notify_by(name, &block) ⇒ Object
Adds a notifier to the array of notifiers to use during the backup process.
-
#perform! ⇒ Object
Performs the backup process.
-
#store_with(storage, &block) ⇒ Object
Adds a storage method to the array of storage methods to use during the backup process.
-
#sync_with(syncer, &block) ⇒ Object
Adds a syncer method to the array of syncer methods to use during the backup process.
Methods included from CLI
Constructor Details
#initialize(trigger, label, &block) ⇒ Model
Takes a trigger, label and the configuration block and instantiates the model. The TIME (time of execution) gets stored in the @time attribute. After the instance has evaluated the configuration block and properly set the configuration for the model, it will append the newly created “model” instance to the @all class variable (Array) so it can be accessed by Backup::Finder and any other location
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/backup/model.rb', line 97 def initialize(trigger, label, &block) @trigger = trigger @label = label @time = TIME @databases = Array.new @archives = Array.new @encryptors = Array.new @compressors = Array.new @storages = Array.new @notifiers = Array.new @syncers = Array.new instance_eval(&block) Backup::Model.all << self end |
Class Attribute Details
.all ⇒ Object
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
53 54 55 |
# File 'lib/backup/model.rb', line 53 def all @all end |
.current ⇒ Object
Contains the currently-in-use model. This attribute should get set by Backup::Finder. Use Backup::Model.current to retrieve the actual data of the model
64 65 66 |
# File 'lib/backup/model.rb', line 64 def current @current end |
.extension ⇒ Object
Contains the current file extension (this changes from time to time after a file gets compressed or encrypted so we can keep track of the correct file when new extensions get appended to the current file name)
59 60 61 |
# File 'lib/backup/model.rb', line 59 def extension @extension end |
Instance Attribute Details
#archives ⇒ Object
The archives attr_accessor holds an array of archive objects
22 23 24 |
# File 'lib/backup/model.rb', line 22 def archives @archives end |
#compressors ⇒ Object
The compressors attr_accessor holds an array of compressor objects
30 31 32 |
# File 'lib/backup/model.rb', line 30 def compressors @compressors end |
#databases ⇒ Object
The databases attribute holds an array of database objects
18 19 20 |
# File 'lib/backup/model.rb', line 18 def databases @databases end |
#encryptors ⇒ Object
The encryptors attr_accessor holds an array of encryptor objects
26 27 28 |
# File 'lib/backup/model.rb', line 26 def encryptors @encryptors end |
#label ⇒ Object
The label is used for a more friendly user output
14 15 16 |
# File 'lib/backup/model.rb', line 14 def label @label end |
#notifiers ⇒ Object
The notifiers attr_accessor holds an array of notifier objects
34 35 36 |
# File 'lib/backup/model.rb', line 34 def notifiers @notifiers end |
#storages ⇒ Object
The storages attribute holds an array of storage objects
38 39 40 |
# File 'lib/backup/model.rb', line 38 def storages @storages end |
#syncers ⇒ Object
The syncers attribute holds an array of syncer objects
42 43 44 |
# File 'lib/backup/model.rb', line 42 def syncers @syncers end |
#time ⇒ Object
The time when the backup initiated (in format: 2011.02.20.03.29.59)
46 47 48 |
# File 'lib/backup/model.rb', line 46 def time @time end |
#trigger ⇒ Object
The trigger is used as an identifier for initializing the backup process
10 11 12 |
# File 'lib/backup/model.rb', line 10 def trigger @trigger end |
Class Method Details
.file ⇒ Object
Returns the full path to the current file (including the current extension). To just return the filename and extension without the path, use File.basename(Backup::Model.file)
69 70 71 |
# File 'lib/backup/model.rb', line 69 def file File.join(TMP_PATH, "#{ TIME }.#{ TRIGGER }.#{ Backup::Model.extension }") end |
.tmp_path ⇒ Object
Returns the temporary trigger path of the current model e.g. /Users/Michael/tmp/backup/my_trigger
76 77 78 |
# File 'lib/backup/model.rb', line 76 def tmp_path File.join(TMP_PATH, TRIGGER) end |
Instance Method Details
#archive(name, &block) ⇒ Object
Adds an archive to the array of archives to store during the backup process
126 127 128 |
# File 'lib/backup/model.rb', line 126 def archive(name, &block) @archives << Backup::Archive.new(name, &block) end |
#compress_with(name, &block) ⇒ Object
Adds a compressor to the array of compressors to use during the backup process
142 143 144 145 146 |
# File 'lib/backup/model.rb', line 142 def compress_with(name, &block) @compressors << Backup::Compressor.const_get( last_constant(name) ).new(&block) end |
#database(database, &block) ⇒ Object
Adds a database to the array of databases to dump during the backup process
117 118 119 120 121 |
# File 'lib/backup/model.rb', line 117 def database(database, &block) @databases << Backup::Database.const_get( last_constant(database) ).new(&block) end |
#encrypt_with(name, &block) ⇒ Object
Adds an encryptor to the array of encryptors to use during the backup process
133 134 135 136 137 |
# File 'lib/backup/model.rb', line 133 def encrypt_with(name, &block) @encryptors << Backup::Encryptor.const_get( last_constant(name) ).new(&block) end |
#notify_by(name, &block) ⇒ Object
Adds a notifier to the array of notifiers to use during the backup process
151 152 153 154 155 |
# File 'lib/backup/model.rb', line 151 def notify_by(name, &block) @notifiers << Backup::Notifier.const_get( last_constant(name) ).new(&block) end |
#perform! ⇒ Object
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
- Package
-
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 one or more encryptors
- Compression
-
Optionally compresses the packaged file with one or more compressors
- 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
-
After the whole backup process finishes, it’ll go ahead and remove any temporary file that it produced. If an exception(error) is raised during this process which breaks the process, it’ll always ensure it removes the temporary files regardless to avoid mass consumption of storage space on the machine
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/backup/model.rb', line 214 def perform! begin if databases.any? or archives.any? databases.each { |d| d.perform! } archives.each { |a| a.perform! } package! compressors.each { |c| c.perform! } encryptors.each { |e| e.perform! } storages.each { |s| s.perform! } clean! end syncers.each { |s| s.perform! } notifiers.each { |n| n.perform!(self) } rescue Exception => exception clean! notifiers.each { |n| n.perform!(self, exception) } show_exception!(exception) end end |