Class: Chef::Knife::TarsnapBackupShow

Inherits:
Chef::Knife show all
Includes:
Chef::Knife::Tarsnap::Core
Defined in:
lib/chef/knife/tarsnap_backup_show.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



27
28
29
30
31
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
# 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