Skip to content

Instantly share code, notes, and snippets.

@ChunAllen
Last active November 28, 2016 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ChunAllen/9e476c901acd82d08cc36feaeeba9e4d to your computer and use it in GitHub Desktop.
Save ChunAllen/9e476c901acd82d08cc36feaeeba9e4d to your computer and use it in GitHub Desktop.
Backup Heroku Database and Restore to Local
$ heroku login --> Login to your Heroku account using CLI
Create latest dump from heroku app
$ heroku pg:backups capture --app [heroku-remote]
$ heroku pg:backups public-url [database_num] --app [app_name]
$ curl -o latest.dump ‘[database_url]'
Restoring to your local
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U [username] -d [database name] latest.dump
@ChunAllen
Copy link
Author

ChunAllen commented Jun 16, 2016

Restoring data from production to staging

Make sure you backup the latest data from production

$ heroku pg:backups public-url [database_num] --app [production_app]

Note:

  • get the latest database_num
  • This command will return database url

$ heroku pg:backups restore [database_url] DATABASE_URL --app [staging_app]

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