class Chef::Knife::TarsnapBackupShow

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/tarsnap_backup_show.rb, line 27
def run

  node_name = name_args.first
  if name_args.size == 2
    archive_name = name_args.last
  elsif name_args.size == 1
    archive_name = nil
  else
    ui.fatal "Must provide only NODE and an option ARCHIVE."
    exit 1
  end

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

    if archive_name.nil?
      list_cmd = "#{tarsnap_tool} --keyfile #{f.path} --list-archives" 
    else
      list_cmd = "#{tarsnap_tool} -t --keyfile #{f.path} -f #{archive_name}"
    end

    list_shell = Mixlib::ShellOut.new(list_cmd, :environment => {'LC_ALL'=>nil})
    list_shell.run_command
    unless list_shell.stderr.empty?
      raise StandardError, "tarsnap error: #{list_shell.stderr}"
    end
    list_shell.stdout.split("\n").sort.each { |l| ui.msg l }
  end

end