Get the database dump from heroku cloud

It's always great to have the relational data in the development phase of a project. The rails applications those are hosted on heroku cloud can easily get the relational data from database. Following are the commands to get the database dump from heroku.

Setp 1: First of all start creating a dump of the database in production using the following command:
heroku pg:backups capture


Step 2: load the database dump that you have created on production:
curl -o latest.dump `heroku pg:backups public-url`
(do it inside the project directory)
If it complains about the app is missing then we need to specify the app name inside the command like below:
curl -o latest.dump `heroku pg:backups public-url --app <appname>`

Setp 3: Once the database dump is downloaded we can easily inject it to the database using the following command:

pg_restore --verbose --clean --no-acl --no-owner 
-h localhost -U USERNAME  -d DATABASENAME latest.dump

Following the heroku documentation for getting postgres database backup to local environment.
Heroku Postgres Backups

Comments