Class: RdiffBackupWrapper::Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/rdiff_backup_wrapper/backup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Backup

Returns a new instance of Backup.



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

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/rdiff_backup_wrapper/backup.rb', line 5

def config
  @config
end

Instance Method Details

#cmdObject



43
44
45
# File 'lib/rdiff_backup_wrapper/backup.rb', line 43

def cmd
  ['rdiff-backup', source, destination]
end

#destinationObject



15
16
17
# File 'lib/rdiff_backup_wrapper/backup.rb', line 15

def destination
  ensure_slash_end('destination')
end

#ensure_slash_end(key) ⇒ Object



19
20
21
22
23
24
# File 'lib/rdiff_backup_wrapper/backup.rb', line 19

def ensure_slash_end(key)
  if config[key].end_with? '/'
    return config[key]
  end
  config[key] + '/'
end

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rdiff_backup_wrapper/backup.rb', line 26

def run
  output = {}

  command = [
    'nice',
    'ionice', '-c', '3',
  ] + cmd

  Open3.popen3(*command) do |i,o,e,t|
      output[:name] = config['name']
      output[:stdout] = o.read
      output[:stderr] = e.read
      output[:retval] = t.value
  end
  output
end

#sourceObject



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

def source
  ensure_slash_end('source')
end

#to_sObject



47
48
49
# File 'lib/rdiff_backup_wrapper/backup.rb', line 47

def to_s
  "<Backup name=#{config['name']}>"
end