Skip to content

Instantly share code, notes, and snippets.

@StanBoyet
Forked from kagemusha/gist:1569836
Last active December 17, 2015 10:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StanBoyet/a6459c3c6eda74d908b0 to your computer and use it in GitHub Desktop.
Save StanBoyet/a6459c3c6eda74d908b0 to your computer and use it in GitHub Desktop.
Dump Heroku Postgres DB and load locally

Get the Heroku db as detailed here: http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup

heroku pg:backups capture
heroku pg:backups --app <you-app-name> #=> <backup_num>
heroku pg:backups public-url <backup_num>  #=> <backup_url>
curl -o db/latest.dump <backup_url>
echo 'db/latest.dump' >> .gitignore # if not already done

Then locally do:

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U <myuser> -d <mydb_name> db/latest.dump

(your database must exist before can do this)

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