Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save resistorsoftware/0a2ed0fe5196d0c5f17611c3a0c52240 to your computer and use it in GitHub Desktop.
Save resistorsoftware/0a2ed0fe5196d0c5f17611c3a0c52240 to your computer and use it in GitHub Desktop.
How to export Heroku Postgres Database to Localhost Database (Rails)?

How to export Heroku Postgres Database to Localhost Database (Rails)?

Step 1

$ cd /path/to/your/rails/app
$ heroku pg:backups capture
$ curl -o latest.dump `heroku pg:backups public-url`

OR

$ curl -o latest.dump `heroku pg:backups public-url --remote <your_remote_name>`

Step 2

Enter app/config/database.yml. Copy your localhost database name.

Example:

development:
  adapter:    postgresql
  database:   YOUR_DATABASE_NAME_HERE
  pool:       5
  timeout:    5000

Step 3

$ rake db:drop db:create db:migrate
$ pg_restore -O -d YOUR_DATABASE_NAME_HERE -c -n public -v latest.dump

OR

$ rake db:drop db:create db:migrate && pg_restore -O -d YOUR_DATABASE_NAME_HERE -c -n public -v latest.dump

Reference: Heroku


Copying Your Production Database to Staging on Heroku

heroku pg:backups restore `heroku pg:backups public-url --app production-app-name` DATABASE --app staging-app-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment