Class: Backup::Adapters::Base
- Inherits:
-
Object
- Object
- Backup::Adapters::Base
- Includes:
- CommandHelper
- Defined in:
- lib/backup/adapters/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#compressed_file ⇒ Object
IMPORTANT final_file must have the value of the final filename result so if a file gets compressed, then the file could look like this: myfile.gz.
-
#encrypt_with_password ⇒ Object
Returns the value of attribute encrypt_with_password.
-
#encrypted_file ⇒ Object
IMPORTANT final_file must have the value of the final filename result so if a file gets compressed, then the file could look like this: myfile.gz.
-
#final_file ⇒ Object
IMPORTANT final_file must have the value of the final filename result so if a file gets compressed, then the file could look like this: myfile.gz.
-
#keep_backups ⇒ Object
Returns the value of attribute keep_backups.
-
#options ⇒ Object
Returns the value of attribute options.
-
#performed_file ⇒ Object
IMPORTANT final_file must have the value of the final filename result so if a file gets compressed, then the file could look like this: myfile.gz.
-
#procedure ⇒ Object
Returns the value of attribute procedure.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
-
#trigger ⇒ Object
Returns the value of attribute trigger.
Instance Method Summary collapse
-
#create_tmp_folder ⇒ Object
Creates the temporary folder for the specified adapter.
-
#encrypt ⇒ Object
Encrypts the archive file.
-
#initialize(trigger, procedure) ⇒ Base
constructor
Initializes the Backup Process.
-
#load_settings ⇒ Object
TODO make methods in derived classes public? respond_to cannot identify private methods.
-
#notify ⇒ Object
Delivers a notification by email regarding the successfully stored backup.
-
#record ⇒ Object
Records data on every individual file to the database.
-
#remove_tmp_files ⇒ Object
Removes the files inside the temporary folder.
-
#store ⇒ Object
Initializes the storing process.
- #system_messages ⇒ Object
Methods included from CommandHelper
Constructor Details
#initialize(trigger, procedure) ⇒ Base
Initializes the Backup Process
This will first load in any prefixed settings from the Backup::Adapters::Base Then it will add it’s own settings.
First it will call the ‘perform’ method. This method is concerned with the backup, and must be implemented by derived classes! Then it will optionally encrypt the backed up file Then it will store it to the specified storage location Then it will record the data to the database Once this is all done, all the temporary files will be removed
Wrapped inside of begin/ensure/end block to ensure the deletion of any files in the tmp directory
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/backup/adapters/base.rb', line 33 def initialize(trigger, procedure) self.trigger = trigger self.procedure = procedure self. = Time.now.strftime("%Y%m%d%H%M%S") self.tmp_path = File.join(BACKUP_PATH.gsub(' ', '\ '), 'tmp', 'backup', trigger) self.encrypt_with_password = procedure.attributes['encrypt_with_password'] self.keep_backups = procedure.attributes['keep_backups'] self.performed_file = "#{}.#{trigger.gsub(' ', '-')}#{performed_file_extension}" self.compressed_file = "#{performed_file}.gz" self.encrypted_file = "#{compressed_file}.enc" self.final_file = compressed_file begin create_tmp_folder load_settings # if respond_to?(:load_settings) perform encrypt store record notify ensure remove_tmp_files end end |
Instance Attribute Details
#compressed_file ⇒ Object
IMPORTANT final_file must have the value of the final filename result so if a file gets compressed, then the file could look like this:
myfile.gz
and if a file afterwards gets encrypted, the file will look like:
myfile.gz.enc
It is important that, whatever the final filename of the file will be, that :final_file will contain it.
18 19 20 |
# File 'lib/backup/adapters/base.rb', line 18 def compressed_file @compressed_file end |
#encrypt_with_password ⇒ Object
Returns the value of attribute encrypt_with_password.
7 8 9 |
# File 'lib/backup/adapters/base.rb', line 7 def encrypt_with_password @encrypt_with_password end |
#encrypted_file ⇒ Object
IMPORTANT final_file must have the value of the final filename result so if a file gets compressed, then the file could look like this:
myfile.gz
and if a file afterwards gets encrypted, the file will look like:
myfile.gz.enc
It is important that, whatever the final filename of the file will be, that :final_file will contain it.
18 19 20 |
# File 'lib/backup/adapters/base.rb', line 18 def encrypted_file @encrypted_file end |
#final_file ⇒ Object
IMPORTANT final_file must have the value of the final filename result so if a file gets compressed, then the file could look like this:
myfile.gz
and if a file afterwards gets encrypted, the file will look like:
myfile.gz.enc
It is important that, whatever the final filename of the file will be, that :final_file will contain it.
18 19 20 |
# File 'lib/backup/adapters/base.rb', line 18 def final_file @final_file end |
#keep_backups ⇒ Object
Returns the value of attribute keep_backups.
7 8 9 |
# File 'lib/backup/adapters/base.rb', line 7 def keep_backups @keep_backups end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/backup/adapters/base.rb', line 7 def @options end |
#performed_file ⇒ Object
IMPORTANT final_file must have the value of the final filename result so if a file gets compressed, then the file could look like this:
myfile.gz
and if a file afterwards gets encrypted, the file will look like:
myfile.gz.enc
It is important that, whatever the final filename of the file will be, that :final_file will contain it.
18 19 20 |
# File 'lib/backup/adapters/base.rb', line 18 def performed_file @performed_file end |
#procedure ⇒ Object
Returns the value of attribute procedure.
7 8 9 |
# File 'lib/backup/adapters/base.rb', line 7 def procedure @procedure end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/backup/adapters/base.rb', line 7 def @timestamp end |
#tmp_path ⇒ Object
Returns the value of attribute tmp_path.
7 8 9 |
# File 'lib/backup/adapters/base.rb', line 7 def tmp_path @tmp_path end |
#trigger ⇒ Object
Returns the value of attribute trigger.
7 8 9 |
# File 'lib/backup/adapters/base.rb', line 7 def trigger @trigger end |
Instance Method Details
#create_tmp_folder ⇒ Object
Creates the temporary folder for the specified adapter
60 61 62 |
# File 'lib/backup/adapters/base.rb', line 60 def create_tmp_folder run "mkdir -p #{tmp_path}" end |
#encrypt ⇒ Object
Encrypts the archive file
74 75 76 77 78 79 80 |
# File 'lib/backup/adapters/base.rb', line 74 def encrypt if encrypt_with_password.is_a?(String) log [:encrypting] run "openssl enc -des-cbc -in #{File.join(tmp_path, compressed_file)} -out #{File.join(tmp_path, encrypted_file)} -k #{encrypt_with_password}" self.final_file = encrypted_file end end |
#load_settings ⇒ Object
TODO make methods in derived classes public? respond_to cannot identify private methods
65 66 |
# File 'lib/backup/adapters/base.rb', line 65 def load_settings end |
#notify ⇒ Object
Delivers a notification by email regarding the successfully stored backup
95 96 97 98 99 |
# File 'lib/backup/adapters/base.rb', line 95 def notify if Backup::Mail::Base.setup? Backup::Mail::Base.notify!(self) end end |
#record ⇒ Object
Records data on every individual file to the database
88 89 90 91 92 |
# File 'lib/backup/adapters/base.rb', line 88 def record record = procedure.initialize_record record.load_adapter(self) record.save end |
#remove_tmp_files ⇒ Object
Removes the files inside the temporary folder
69 70 71 |
# File 'lib/backup/adapters/base.rb', line 69 def remove_tmp_files run "rm #{File.join(tmp_path, '*')}" end |
#store ⇒ Object
Initializes the storing process
83 84 85 |
# File 'lib/backup/adapters/base.rb', line 83 def store procedure.initialize_storage(self) end |
#system_messages ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/backup/adapters/base.rb', line 101 def { :compressing => "Compressing backup..", :archiving => "Archiving backup..", :encrypting => "Encrypting backup..", :mysqldump => "Creating MySQL dump..", :pgdump => "Creating PostgreSQL dump..", :sqlite => "Copying and compressing SQLite database..", :commands => "Executing commands.." } end |