Pg backups curl latest dump from Heroku

1.1k Views Asked by At

How can I download the latest backup from Heroku in a single line command. The code has recently changed and doesn't seem to be of much help. https://devcenter.heroku.com/articles/heroku-postgres-import-export

This creates a public url that i can open and download

$ heroku pg:backups public-url | cat

I need to use the curl command to download it, but it does not work

$ curl -o latest.dump heroku pg:backups public-url | cat

I have also tried to use the following and it could not resolve host.

heroku pg:backups capture && curl -o latest.dump `heroku pg:backups public-url | cat`

heroku pg:backups public-url && curl -o latest.dump `heroku pg:backups public-url | cat`

Please assist with the full command line.

2

There are 2 best solutions below

1
On

Ran into the same issue but was able to figure out a workaround:

$: heroku pg:backups capture --app APP_NAME

This will return a backup to something like b001

$: heroku pg:backups public-url b002 --app APP_NAME | cat

Returns url to dump

$  curl -o latest.dump URL_FROM_DUMP

$: pg_restore latest.dump -d YOUR_DB_NAME
0
On

This helped me import my Heroku Postgres db with all tables data(rows) to my local Postgres db:

  1. Back up your database from Heroku
heroku pg:backups:capture -a your-app-name
  1. Download the database from Heroku. The database will be downloaded as a latest.dump file to your computer
heroku pg:backups:download -a your-app-name
  1. Import latest.dump to Postgres (your local database) (if this is the first dump, you don't need to specify the number of dump)
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U your_local_db_username -d your_local_db_name latest.dump.[number of dump] 

For number of dump look carefully on your console during step 2. For some reason Heroku documentation doesn't say anything about the number of dump.