Class: Chef::Knife::TarsnapBackupDownload

Inherits:
Chef::Knife
  • Object
show all
Includes:
Chef::Knife::Tarsnap::Core
Defined in:
lib/chef/knife/tarsnap_backup_download.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
62
63
64
65
# File 'lib/chef/knife/tarsnap_backup_download.rb', line 32

def run

  unless name_args.size == 2
    ui.fatal "Must provide only NODE and ARCHIVE."
    exit 1
  end

  node_name = name_args[0]
  archive_name = name_args[1]

  tarball = config[:save_to] || File.join(Dir.pwd, "#{archive_name}.tar")

  if File.exists?(tarball)
    ui.warn "A file named #{tarball} already exists. Do you want to overwrite it?"
    ui.confirm "Overwrite"
  end

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

    list_cmd = "#{tarsnap_tool} --keyfile #{f.path} -r -f #{archive_name} > #{tarball}"

    ui.msg "Downloading #{tarball}..."
    list_shell = Mixlib::ShellOut.new(list_cmd, :timeout => 604800)
    list_shell.run_command
    unless list_shell.status.exitstatus == 0
      raise StandardError, "tarsnap error: #{list_shell.stderr}"
    end
    ui.msg "#{tarball} saved."
  end

end