Class: Backup::Storage::Base

Inherits:
Object
  • Object
show all
Includes:
Configuration::Helpers
Defined in:
lib/backup/storage/base.rb

Direct Known Subclasses

CloudFiles, Dropbox, FTP, RSync, S3, SCP, SFTP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configuration::Helpers

#clear_defaults!, #getter_methods, #load_defaults!, #setter_methods

Instance Attribute Details

#keepObject

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

#timeObject

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.message "#{ self.class } started removing (cycling) \"#{ object.remote_file }\"."
      object.send(:remove!)
    end
    objects = objects - objects_to_remove
  end
  storage_object.write(objects)
end

#local_fileObject

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_pathObject

Returns the local path



19
20
21
# File 'lib/backup/storage/base.rb', line 19

def local_path
  TMP_PATH
end

#providerObject

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_fileObject

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