lib/heroku/command/pgbackups.rb
# pgbackups:capture [DATABASE]
#
# capture a backup from a database id
#
# if no DATABASE is specified, defaults to DATABASE_URL
#
# -e, --expire  # if no slots are available, destroy the oldest manual backup to make room
#
capture [DATABASE]
capture a backup from a database id

if no DATABASE is specified, defaults to DATABASE_URL

e, --expire  # if no slots are available, destroy the oldest manual backup to make room
capture [ DATABASE ] capture a backup from a database id if no DATABASE is specified defaults to DATABASE_URL e -- expire # if no slots are available destroy the oldest manual backup to make room
def capture
      attachment = resolve(shift_argument, "DATABASE_URL")
      validate_arguments!
      from_name = attachment.display_name
      from_url  = attachment.url
      to_url    = nil 
      to_name   = "BACKUP"
      opts      = {:expire => options[: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#{from_name}  ----backup--->  #{backup_id}"
      backup = poll_transfer!(backup)
      if backup["error_at"]
        message  =   "An error occurred and your backup did not finish."
        message += "\nPlease run `heroku logs --ps pgbackups` for details."
        message += "\nThe database is not yet online. Please try again." if backup['log'] =~ /Name or service not known/
        message += "\nThe database credentials are incorrect."           if backup['log'] =~ /psql: FATAL:/
        error(message)
      end
    end
def capture attachment = resolve ( shift_argument , "DATABASE_URL" ) validate_arguments! from_name = attachment . display_name from_url = attachment . url to_url = nil to_name = "BACKUP" opts = { :expire => options [ :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#{from_name}  ----backup--->  #{backup_id}" backup = poll_transfer! ( backup ) if backup [ "error_at" ] message = "An error occurred and your backup did not finish." message += "\nPlease run `heroku logs --ps pgbackups` for details." message += "\nThe database is not yet online. Please try again." if backup [ 'log' ] =~ / Name or service not known / message += "\nThe database credentials are incorrect." if backup [ 'log' ] =~ / psql: FATAL: / error ( message ) end end
pgbackups:capture [DATABASE]
capture a backup from a database id
pgbackups : capture [ DATABASE ] capture a backup from a database id
# server will assign