zulhfreelancer
4/1/2016 - 6:31 AM

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

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
$ pg_restore -O -d YOUR_DATABASE_NAME_HERE latest.dump
$ rake db:migrate

OR

$ rake db:drop db:create; pg_restore -O -d YOUR_DATABASE_NAME_HERE latest.dump; rake db:migrate

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