class Rudy::Backup
Public Class Methods
new(position=nil, path=nil, opts={})
click to toggle source
If one argument is supplied:
-
path
is a an absolute filesystem path -
opts
is a hash of disk options.
If two arguments are supplied:
-
position
-
path
is a an absolute filesystem path -
opts
is a hash of disk options.
Valid options are:
-
:path
is a an absolute filesystem path (overridden bypath
arg) -
:position
(overridden byposition
arg) -
:created
is an instance of Time -
:user
is the name of the user which created the backup.
Calls superclass method
Rudy::Metadata.new
# File lib/rudy/metadata/backup.rb, line 42 def initialize(position=nil, path=nil, opts={}) # Swap arg values if only one is supplied. path, position = position, nil if !position.nil? && path.nil? position ||= '01' opts = { :created => Time.now.utc, :user => Rudy.sysinfo.user }.merge opts super Rudy::Backups::RTYPE, opts # Rudy::Metadata#initialize @position, @path = position, path postprocess end
Public Instance Methods
any?()
click to toggle source
Are there any backups for the associated disk?
# File lib/rudy/metadata/backup.rb, line 114 def any? backups = Rudy::Backups.list self.descriptors, [:year, :month, :day, :hour, :second] !backups.nil? end
create()
click to toggle source
# File lib/rudy/metadata/backup.rb, line 92 def create raise DuplicateRecord, self.name if exists? disk = self.disk ld "DISK: #{disk.name}" raise Rudy::Backups::NoDisk, disk.name unless disk.exists? @volid ||= disk.volid snap = Rudy::AWS::EC2::Snapshots.create(@volid) #snap = Rudy::AWS::EC2::Snapshots.list.first # debugging ld "SNAP: #{snap.inspect}" @snapid, @raw = snap.awsid, true @size, @fstype = disk.size, disk.fstype self.save :replace self end
date()
click to toggle source
# File lib/rudy/metadata/backup.rb, line 84 def date "%s%s%s" % [@year, @month, @day] end
descriptors()
click to toggle source
Calls superclass method
Rudy::Metadata#descriptors
# File lib/rudy/metadata/backup.rb, line 119 def descriptors super :position, :path, :year, :month, :day, :hour, :second end
destroy()
click to toggle source
Calls superclass method
Rudy::Metadata.destroy
# File lib/rudy/metadata/backup.rb, line 123 def destroy Rudy::AWS::EC2::Snapshots.destroy(@snapid) if snapshot_exists? super() end
disk()
click to toggle source
# File lib/rudy/metadata/backup.rb, line 132 def disk opts = { :region => @region, :zone => @zone, :environment => @environment, :role => @role, :size => @size, :fstype => @fstype } disk = Rudy::Disk.new @position, @path, opts disk.refresh! if disk.exists? disk.size = @size disk.fstype = @fstype disk end
disk_exists?()
click to toggle source
# File lib/rudy/metadata/backup.rb, line 145 def disk_exists? self.disk.exists? end
name()
click to toggle source
Calls superclass method
Rudy::Metadata#name
# File lib/rudy/metadata/backup.rb, line 74 def name sep = File::SEPARATOR dirs = @path.split sep if @path && !@path.empty? unless @path == File::SEPARATOR dirs.shift while dirs && (dirs[0].nil? || dirs[0].empty?) end # Calls Rudy::Metadata#name with backup specific components super [dirs, date, time, second] end
postprocess()
click to toggle source
# File lib/rudy/metadata/backup.rb, line 60 def postprocess @position &&= @position.to_s.rjust(2, '0') @year = @created.year @month = @created.month.to_s.rjust(2, '0') @day = @created.mday.to_s.rjust(2, '0') @hour = @created.hour.to_s.rjust(2, '0') @minute = @created.min.to_s.rjust(2, '0') @second = @created.sec.to_s.rjust(2, '0') end
restore()
click to toggle source
# File lib/rudy/metadata/backup.rb, line 107 def restore raise UnknownObject, self.name unless exists? raise Rudy::Backups::NoBackup, self.name unless any? end
time()
click to toggle source
# File lib/rudy/metadata/backup.rb, line 88 def time "%s%s" % [@hour, @minute] end
to_s(*args)
click to toggle source
# File lib/rudy/metadata/backup.rb, line 70 def to_s(*args) [self.name.bright, self.snapid, self.volid, self.size, self.fstype].join '; ' end
valid?()
click to toggle source
# File lib/rudy/metadata/backup.rb, line 128 def valid? !@path.nil? && !@path.empty? && @created.is_a?(Time) && !@volid.nil? end