Skip to content

Instantly share code, notes, and snippets.

@codyhanson
Last active August 29, 2015 14:06
Show Gist options
  • Save codyhanson/7b392cd5492016eae74e to your computer and use it in GitHub Desktop.
Save codyhanson/7b392cd5492016eae74e to your computer and use it in GitHub Desktop.
Restore heroku pgdump to local database, and work with copies.

Download the Heroku backup that you want

Get list of backups

heroku pgbackups --app $APP

Get url for backup, and download

heroku pgbackups:url $backupId --app $APP
wget $theBackupUrl

Restore the backup to a db

createdb dbname
pg_restore -d dbname $dumpFile

change which db you are using

psql=> \c dbname

Then, to move that and clone it to a new db with a different name (connections to the cloned DB need to be stopped):

CREATE DATABASE $newDb WITH TEMPLATE $dbYouAreCopying OWNER $owner;

list your dbs to you can see that it worked

psql=> \l

To pull directly from Heroku:

 heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb --app sushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment