def save_snapshot(app, filename, for_deployment=false, ssh_executable=nil)
ssh_uri = URI.parse(app.ssh_url)
ssh_executable = check_ssh_executable! ssh_executable
snapshot_cmd = for_deployment ? 'gear archive-deployment' : 'snapshot'
ssh_cmd = "#{ssh_executable} #{ssh_uri.user}@#{ssh_uri.host} '#{snapshot_cmd}' > #{filename}"
ssh_stderr = " 2>/dev/null"
debug ssh_cmd
say "Pulling down a snapshot of application '#{app.name}' to #{filename} ... "
begin
if !RHC::Helpers.windows?
status, output = exec(ssh_cmd + (debug? ? '' : ssh_stderr))
if status != 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_cmd 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
success 'done'
end