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 by path arg)
:position (overridden by position arg)
:created is an instance of Time
:user is the name of the user which created the backup.
# 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
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
# 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
# File lib/rudy/metadata/backup.rb, line 84 def date "%s%s%s" % [@year, @month, @day] end
# File lib/rudy/metadata/backup.rb, line 119 def descriptors super :position, :path, :year, :month, :day, :hour, :second end
# File lib/rudy/metadata/backup.rb, line 123 def destroy Rudy::AWS::EC2::Snapshots.destroy(@snapid) if snapshot_exists? super() end
# 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
# File lib/rudy/metadata/backup.rb, line 145 def disk_exists? self.disk.exists? end
# 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
# 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
# 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
# File lib/rudy/metadata/backup.rb, line 88 def time "%s%s" % [@hour, @minute] end
Generated with the Darkfish Rdoc Generator 2.