Class: RdiffBackupWrapper::LuksLoopVolume

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

Instance Attribute Summary

Attributes inherited from Volume

#config

Instance Method Summary collapse

Methods inherited from Volume

#check_error, create, #initialize

Constructor Details

This class inherits a constructor from RdiffBackupWrapper::Volume

Instance Method Details

#cleanupObject



63
64
65
66
67
68
69
70
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 63

def cleanup
  if mounted?
    cleanup_mount
  end
  if luks_exists?
    cleanup_luks
  end
end

#cleanup_luksObject



15
16
17
18
19
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 15

def cleanup_luks
  Open3.popen3("cryptsetup", "luksClose", luks_name) do |i, o, e ,t|
    check_error(o, e, t)
  end
end

#cleanup_mountObject



52
53
54
55
56
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 52

def cleanup_mount
  Open3.popen3("umount", config['mountPoint']) do |i, o, e ,t|
    check_error(o, e, t)
  end
end

#luks_exists?Boolean



33
34
35
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 33

def luks_exists?
  File.exists? luks_path
end

#luks_nameObject



21
22
23
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 21

def luks_name
  config['name']
end

#luks_pathObject



29
30
31
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 29

def luks_path
  File.join('/dev/mapper', luks_name)
end

#luks_sourceObject



25
26
27
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 25

def luks_source
  config['imagePath']
end

#mounted?Boolean



37
38
39
40
41
42
43
44
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 37

def mounted?
  Open3.popen3("mountpoint", "-q", config['mountPoint']) do |i, o, e ,t|
    if t.value.exitstatus == 0
      return true
    end
  end
  return false
end

#prepareObject



58
59
60
61
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 58

def prepare
  prepare_luks
  prepare_mount
end

#prepare_luksObject



7
8
9
10
11
12
13
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 7

def prepare_luks
  Open3.popen3("cryptsetup", "luksOpen", luks_source, luks_name) do |i, o, e ,t|
    i.puts "#{config['luksKey']}\n"
    i.close
    check_error(o, e, t)
  end
end

#prepare_mountObject



46
47
48
49
50
# File 'lib/rdiff_backup_wrapper/luks_loop_volume.rb', line 46

def prepare_mount
  Open3.popen3("mount", luks_path, config['mountPoint']) do |i, o, e ,t|
    check_error(o, e, t)
  end
end