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) add pgbackups add-on to production and staging apps
heroku addons:add pgbackups:basic --app production-app
heroku addons:add pgbackups:basic --app staging-app
Since I am only using pgbackups for migration, basic plan is enough for this.
2) Create the backup for the production-app db
heroku pgbackups:capture --app production-app
This will generate b001 backup file from the main database (usually production db in database.yml)
3) To view all the backups (OPTIONAL)
heroku pgbackups --app production-app
4) Now use the pgbackups:restore command to populate staging server database from the last backup file on production server
heroku pgbackups:restore DATABASE `heroku pgbackups:url --app production-app` --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.
No comments:
Post a Comment