Methods
public class
public instance
Included modules
- Rudy::Metadata
- Gibbler::Complex
Public class methods
new
(position=nil, path=nil, opts={})
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.
[show source]
# File lib/rudy/metadata/backup.rb, line 42 42: def initialize(position=nil, path=nil, opts={}) 43: # Swap arg values if only one is supplied. 44: path, position = position, nil if !position.nil? && path.nil? 45: position ||= '01' 46: 47: opts = { 48: :created => Time.now.utc, 49: :user => Rudy.sysinfo.user 50: }.merge opts 51: 52: super Rudy::Backups::RTYPE, opts # Rudy::Metadata#initialize 53: 54: @position, @path = position, path 55: 56: postprocess 57: 58: end
Public instance methods
any?
()
Are there any backups for the associated disk?
[show source]
# File lib/rudy/metadata/backup.rb, line 114 114: def any? 115: backups = Rudy::Backups.list self.descriptors, [:year, :month, :day, :hour, :second] 116: !backups.nil? 117: end
create
()
[show source]
# File lib/rudy/metadata/backup.rb, line 92 92: def create 93: raise DuplicateRecord, self.name if exists? 94: disk = self.disk 95: ld "DISK: #{disk.name}" 96: raise Rudy::Backups::NoDisk, disk.name unless disk.exists? 97: @volid ||= disk.volid 98: snap = Rudy::AWS::EC2::Snapshots.create(@volid) 99: #snap = Rudy::AWS::EC2::Snapshots.list.first # debugging 100: ld "SNAP: #{snap.inspect}" 101: @snapid, @raw = snap.awsid, true 102: @size, @fstype = disk.size, disk.fstype 103: self.save :replace 104: self 105: end
date
()
[show source]
# File lib/rudy/metadata/backup.rb, line 84 84: def date 85: "%s%s%s" % [@year, @month, @day] 86: end
descriptors
()
[show source]
# File lib/rudy/metadata/backup.rb, line 119 119: def descriptors 120: super :position, :path, :year, :month, :day, :hour, :second 121: end
destroy
()
[show source]
# File lib/rudy/metadata/backup.rb, line 123 123: def destroy 124: Rudy::AWS::EC2::Snapshots.destroy(@snapid) if snapshot_exists? 125: super() 126: end
disk
()
[show source]
# File lib/rudy/metadata/backup.rb, line 132 132: def disk 133: opts = { 134: :region => @region, :zone => @zone, 135: :environment => @environment, :role => @role, 136: :size => @size, :fstype => @fstype 137: } 138: disk = Rudy::Disk.new @position, @path, opts 139: disk.refresh! if disk.exists? 140: disk.size = @size 141: disk.fstype = @fstype 142: disk 143: end
disk_exists?
()
[show source]
# File lib/rudy/metadata/backup.rb, line 145 145: def disk_exists? 146: self.disk.exists? 147: end
name
()
[show source]
# File lib/rudy/metadata/backup.rb, line 74 74: def name 75: sep = File::SEPARATOR 76: dirs = @path.split sep if @path && !@path.empty? 77: unless @path == File::SEPARATOR 78: dirs.shift while dirs && (dirs[0].nil? || dirs[0].empty?) 79: end 80: # Calls Rudy::Metadata#name with backup specific components 81: super [dirs, date, time, second] 82: end
postprocess
()
[show source]
# File lib/rudy/metadata/backup.rb, line 60 60: def postprocess 61: @position &&= @position.to_s.rjust(2, '0') 62: @year = @created.year 63: @month = @created.month.to_s.rjust(2, '0') 64: @day = @created.mday.to_s.rjust(2, '0') 65: @hour = @created.hour.to_s.rjust(2, '0') 66: @minute = @created.min.to_s.rjust(2, '0') 67: @second = @created.sec.to_s.rjust(2, '0') 68: end
restore
()
[show source]
# File lib/rudy/metadata/backup.rb, line 107 107: def restore 108: raise UnknownObject, self.name unless exists? 109: raise Rudy::Backups::NoBackup, self.name unless any? 110: 111: end
time
()
[show source]
# File lib/rudy/metadata/backup.rb, line 88 88: def time 89: "%s%s" % [@hour, @minute] 90: end
to_s
(*args)
[show source]
# File lib/rudy/metadata/backup.rb, line 70 70: def to_s(*args) 71: [self.name.bright, self.snapid, self.volid, self.size, self.fstype].join '; ' 72: end
valid?
()
[show source]
# File lib/rudy/metadata/backup.rb, line 128 128: def valid? 129: !@path.nil? && !@path.empty? && @created.is_a?(Time) && !@volid.nil? 130: end