class Chef::Knife::TarsnapBackupDump

Public Instance Methods

run() click to toggle source
# 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