Class: Chef::Knife::TarsnapBackupDump

Inherits:
Chef::Knife show all
Includes:
Chef::Knife::Tarsnap::Core
Defined in:
lib/chef/knife/tarsnap_backup_dump.rb

Instance Method Summary collapse

Methods included from Chef::Knife::Tarsnap::Core

#canonicalize, #fetch_key, #fetch_node, included, #is_a_tarsnap_node?, #keygen_tool, #pending_nodes, #remove_pending_node, #tarsnap_data_bag, #tarsnap_nodes, #tarsnap_password, #tarsnap_tool, #tarsnap_username

Instance Method Details

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/knife/tarsnap_backup_dump.rb', line 32

def run

  if name_args.size == 3
    node_name = name_args[0]
    archive_name = name_args[1]
    filename = name_args.last
  else
    ui.fatal "Incorrect number of options provided"
    exit 1
  end

  Tempfile.open('tarsnap', '/tmp') do |f|
    key = fetch_key(node_name)
    f.write(key)
    f.close

    if config[:directory]
      dump_cmd = "#{tarsnap_tool} --keyfile #{f.path} -x -f #{archive_name} -C #{config[:directory]} --include '#{filename}'"
    else
      dump_cmd = "#{tarsnap_tool} --keyfile #{f.path} -x -f #{archive_name} -O --include '#{filename}'"
    end
    dump_shell = Mixlib::ShellOut.new(dump_cmd, :timeout => 604800, :environment => {'LC_ALL'=>nil})
    dump_shell.run_command
    unless dump_shell.status.exitstatus == 0
      raise StandardError, "tarsnap error: #{dump_shell.stderr}"
    end
    ui.msg dump_shell.stdout
  end

end