def save(app)
rest_app = rest_client.find_application(options.namespace, app)
ssh_uri = URI.parse(rest_app.ssh_url)
filename = options.filepath ? options.filepath : "#{app}.tar.gz"
ssh_cmd = "ssh #{ssh_uri.user}@#{ssh_uri.host} 'snapshot' > #{filename}"
debug ssh_cmd
say "Pulling down a snapshot to #{filename}..."
begin
if ! RHC::Helpers.windows?
output = Kernel.send(:`, ssh_cmd)
if $?.exitstatus != 0
debug output
raise RHC::SnapshotSaveException.new "Error in trying to save snapshot. You can try to save manually by running:\n#{ssh_cmd}"
end
else
Net::SSH.start(ssh_uri.host, ssh_uri.user) do |ssh|
File.open(filename, 'wb') do |file|
ssh.exec! "snapshot" do |channel, stream, data|
if stream == :stdout
file.write(data)
else
debug data
end
end
end
end
end
rescue Timeout::Error, Errno::EADDRNOTAVAIL, Errno::EADDRINUSE, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Net::SSH::AuthenticationFailed => e
debug e.backtrace
raise RHC::SnapshotSaveException.new "Error in trying to save snapshot. You can try to save manually by running:\n#{ssh_cmd}"
end
results { say "Success" }
0
end