Skip to content

Instantly share code, notes, and snippets.

@dirkgroenen
Forked from wrburgess/gist:5528649
Last active July 8, 2023 05:13
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dirkgroenen/07c3e8e4bc7e08bc3232ae0bdd6a0ba5 to your computer and use it in GitHub Desktop.
Save dirkgroenen/07c3e8e4bc7e08bc3232ae0bdd6a0ba5 to your computer and use it in GitHub Desktop.
Backup Heroku Postgres database and restore to local database

Grab new backup of database

Command: heroku pgbackups:capture --remote production

Response: >>> HEROKU_POSTGRESQL_COLOR_URL (DATABASE_URL) ----backup---> a712

Get url of backup download

Command: heroku pgbackups:url [db_key] --remote production

Example: heroku pgbackups:url a712 --remote production

>>> "https://s3.amazonaws.com/hkpgbackups/app11111118@heroku.com/a712.dump?AWSAccessKeyId=XXXXXXXXXXXXXX&Expires=1367876175&Signature=XXXXXXX%EEEEEEEYWWWWWWW%3D"

Download backup dump file

Command: curl "http://[url]" > production.dump

Example: curl "https://s3.amazonaws.com/hkpgbackups/app11111118@heroku.com/a712.dump?AWSAccessKeyId=XXXXXXXXXXXXXX&Expires=1367876175&Signature=XXXXXXX%EEEEEEEYWWWWWWW%3D" > production.dump

Restore backup dump into local db

Command: pg_restore --verbose --clean --no-acl --no-owner -h localhost -d [db_name] production.dump

@heardofdezz
Copy link

What about the other way arround importing data from a local server to heroku posgresql server ?

@remy727
Copy link

remy727 commented Jun 14, 2022

@dirkgroenen, Heroku postgres command is updated.
Before:
heroku pgbackups:capture
Now:
heroku pg:backups:capture

@SalahAdDin
Copy link

Does this work with Heroku dashboard-generated backups?

@martonczirjak
Copy link

Does this work with Heroku dashboard-generated backups? I want to know also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment