Class: PrlBackup::Backup

Inherits:
Object
  • Object
show all
Extended by:
PrlBackup
Includes:
Comparable, PrlBackup
Defined in:
lib/prlbackup/backup.rb

Constant Summary

Constants included from PrlBackup

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PrlBackup

conditionally_run, logger, run

Constructor Details

#initialize(properties) ⇒ Backup

Returns a new instance of Backup.



42
43
44
# File 'lib/prlbackup/backup.rb', line 42

def initialize(properties)
  @properties = properties
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



40
41
42
# File 'lib/prlbackup/backup.rb', line 40

def properties
  @properties
end

Class Method Details

.all(uuid) ⇒ Object



7
8
9
# File 'lib/prlbackup/backup.rb', line 7

def all(uuid)
  backup_list(uuid).split("\n").map { |b| create(b) }.compact.sort
end

.backup_list(uuid) ⇒ Object



11
12
13
# File 'lib/prlbackup/backup.rb', line 11

def backup_list(uuid)
  run('prlctl', 'backup-list', uuid)
end

.create(line) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/prlbackup/backup.rb', line 15

def create(line)
  re = /^
    (\{[0-9a-f-]+\})        # VM UUID
    \s+
    (\{[0-9a-f-]+\}[\.\d]*) # Backup UUID
    \s+
    (\S+)                   # Node
    \s+
    ([\d\/]+\s[\d:]+)       # Time
    \s+
    ([fi])                  # Type
    \s+
    (\d+)                   # Size
  $/x
  new(:uuid => $2, :time => $4, :type => $5) if re.match(line)
end

.to_sObject



32
33
34
# File 'lib/prlbackup/backup.rb', line 32

def to_s
  'Backup'
end

Instance Method Details

#<=>(other) ⇒ Object



62
63
64
# File 'lib/prlbackup/backup.rb', line 62

def <=>(other)
  time <=> other.time
end

#deleteObject



58
59
60
# File 'lib/prlbackup/backup.rb', line 58

def delete
  conditionally_run('prlctl', 'backup-delete', '--tag', uuid)
end

#full?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/prlbackup/backup.rb', line 54

def full?
  properties[:type] == 'f'
end

#timeObject



50
51
52
# File 'lib/prlbackup/backup.rb', line 50

def time
  DateTime.strptime(properties[:time], '%m/%d/%Y %H:%M:%S')
end

#to_sObject

Display time of backup.



67
68
69
70
71
# File 'lib/prlbackup/backup.rb', line 67

def to_s
  "#{self.class.to_s}: #{time.strftime('%Y-%m-%d %H:%M:%S')}"
rescue ArgumentError
  "#{self.class.to_s}: Unknown"
end

#uuidObject



46
47
48
# File 'lib/prlbackup/backup.rb', line 46

def uuid
  properties[:uuid]
end