def capture
expire = extract_option("--expire")
db_id = args.shift
from_name, from_url = resolve_db_id(db_id, :default => "DATABASE_URL")
db_id ||= "DATABASE_URL"
abort(" ! No database addon detected.") unless from_url
to_name = "BACKUP"
to_url = nil
opts = {}
opts[:expire] = true if expire
backup = transfer!(from_url, from_name, to_url, to_name, opts)
to_uri = URI.parse backup["to_url"]
backup_id = to_uri.path.empty? ? "error" : File.basename(to_uri.path, '.*')
display "\n#{db_id} ----backup---> #{backup_id}"
backup = poll_transfer!(backup)
if backup["error_at"]
message = " ! An error occurred and your backup did not finish."
message += "\n ! The database is not yet online. Please try again." if backup['log'] =~ /Name or service not known/
message += "\n ! The database credentials are incorrect." if backup['log'] =~ /psql: FATAL:/
abort(message)
end
end