Class: Backup::Storage::Base
- Inherits:
-
Object
- Object
- Backup::Storage::Base
- Includes:
- Configuration::Helpers
- Defined in:
- lib/backup/storage/base.rb
Instance Attribute Summary collapse
-
#keep ⇒ Object
Sets the limit to how many backups to keep in the remote location.
-
#time ⇒ Object
The time when the backup initiated (in format: 2011.02.20.03.29.59).
Instance Method Summary collapse
-
#cycle! ⇒ Object
Checks the persisted storage data by type (S3, CloudFiles, SCP, etc) to see if the amount of stored backups is greater than the amount of backups allowed.
-
#local_file ⇒ Object
Returns the local archive filename.
-
#local_path ⇒ Object
Returns the local path.
-
#provider ⇒ Object
Provider defaults to false and will be overridden when using a service-based storage such as Amazon S3, Rackspace Cloud Files or Dropbox.
-
#remote_file ⇒ Object
Returns the name of the file that’s stored on the remote location.
Methods included from Configuration::Helpers
#clear_defaults!, #getter_methods, #load_defaults!, #setter_methods
Instance Attribute Details
#keep ⇒ Object
Sets the limit to how many backups to keep in the remote location. If the limit exceeds it will remove the oldest backup to make room for the newest
15 16 17 |
# File 'lib/backup/storage/base.rb', line 15 def keep @keep end |
#time ⇒ Object
The time when the backup initiated (in format: 2011.02.20.03.29.59)
10 11 12 |
# File 'lib/backup/storage/base.rb', line 10 def time @time end |
Instance Method Details
#cycle! ⇒ Object
Checks the persisted storage data by type (S3, CloudFiles, SCP, etc) to see if the amount of stored backups is greater than the amount of backups allowed. If this is the case it’ll invoke the #remove! method on each of the oldest backups that exceed the storage limit (specified by @keep). After that it’ll re-assign the objects variable with an array of objects that still remain after the removal of the older objects and files (that exceeded the @keep range). And finally these remaining objects will be converted to YAML format and are written back to the YAML file
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/backup/storage/base.rb', line 50 def cycle! type = self.class.name.split("::").last storage_object = Backup::Storage::Object.new(type) objects = [self] + storage_object.load if keep.is_a?(Integer) and keep > 0 and objects.size > keep objects_to_remove = objects[keep..-1] objects_to_remove.each do |object| Logger. "#{ self.class } started removing (cycling) \"#{ object.remote_file }\"." object.send(:remove!) end objects = objects - objects_to_remove end storage_object.write(objects) end |
#local_file ⇒ Object
Returns the local archive filename
25 26 27 |
# File 'lib/backup/storage/base.rb', line 25 def local_file @local_file ||= File.basename(Backup::Model.file) end |
#local_path ⇒ Object
Returns the local path
19 20 21 |
# File 'lib/backup/storage/base.rb', line 19 def local_path TMP_PATH end |
#provider ⇒ Object
Provider defaults to false and will be overridden when using a service-based storage such as Amazon S3, Rackspace Cloud Files or Dropbox
38 39 40 |
# File 'lib/backup/storage/base.rb', line 38 def provider false end |
#remote_file ⇒ Object
Returns the name of the file that’s stored on the remote location
31 32 33 |
# File 'lib/backup/storage/base.rb', line 31 def remote_file @remote_file ||= local_file end |