Skip to content

Instantly share code, notes, and snippets.

@jeffjohnson9046
Created March 31, 2015 18:55
Show Gist options
  • Save jeffjohnson9046/ec5ddb27e8568a527cfa to your computer and use it in GitHub Desktop.
Save jeffjohnson9046/ec5ddb27e8568a527cfa to your computer and use it in GitHub Desktop.
Heroku: Take Database Backup and Restore Locally
# NOTE: These steps assume the following:
# * The heroku toolbelt is installed: https://toolbelt.heroku.com/
# * A postgres server is installed and running: http://www.enterprisedb.com/products-services-training/pgdownload#osx
# STEP 1: Login to herku:
heroku login
# provide credentials
# STEP 2: Create database backup
heroku pg:backups public-url b001 --app <the name of your heroku application>
# This command will spit out a URL that is good for 10 minutes:
# https://xfrtu.s3.amazonaws.com/...[some incredibly convoluted and hard-to-guess URL]
# STEP 3: Download the backup file using curl (or wget or whatever):
curl [the incredibly convoluted and hard-to-guess URL] -o [some filename that you can remember]
# STEP 4: Restore the backup to your local Postgres database.
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U [postgres user name, usually postgres] -d [the name of your database] [the name of your backup file created in Step 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment