transfer db from one heroku app to another faster transfer db from one heroku app to another faster ruby ruby

transfer db from one heroku app to another faster


It's quite common to migrate databases between staging, testing and production environments for Rails Apps. And heroku db:pull/push is painfully slow. The best way I have found so far is using Heroku PG Backups add-on and it's free. I followed following steps to migrate production database to staging server:

1) Create the backup for the production-app db

heroku pg:backups capture --app production-app

This will generate b001 backup file from the main database (usually production db in database.yml)

2) To view all the backups (OPTIONAL)

heroku pg:backups --app production-app

3) Now use the pg:backups restore command to populate staging server database from the last backup file on production server

heroku pg:backups restore $(heroku pg:backups public-url --app production-app) DATABASE_URL --app staging-app

Remember that restore is a destructive operation, it will delete existing data before replacing it with the contents of the backup file.


So things are even easier now .. checkout the transfer command as part of pgbackups

heroku pgbackups:transfer HEROKU_POSTGRESQL_PINK sushi-staging::HEROKU_POSTGRESQL_OLIVE -a sushi

https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases#4b-alternative-transfer-data-between-applications

This has worked beautifully for me taking production code back to my staging site.


The correct answer has changed again as of March 11, 2015.

heroku pg:backups restore $(heroku pg:backups public-url --app myapp-production) DATABASE_URL --app myapp-staging

Note specifically that the argument is now public-url.

https://blog.heroku.com/archives/2015/3/11/pgbackups-levels-up