How do I transfer production database to staging on Heroku using pgbackups? Getting error

后端 未结 12 2173
刺人心
刺人心 2021-01-30 03:13

On Heroku, I am trying to copy the production database into my staging app using the pgbackups addon. I followed the instructions on the addon page: https://devcenter.heroku.com

相关标签:
12条回答
  • 2021-01-30 03:42

    Here's a simple and safe solution to this using Heroku's add-on attachments and forking. It does not require backups, no downtime, and does not overwrite any database.

    You need to attach the production database to the staging app first, then fork on the staging app. If you fork on the production app, then attach to the staging app, the billing app will be the production app and you won't be able to detach the fork from it.

    1. First find out the add-on name of your production database (here it is postgres-prod-123):

    $ heroku addons --app myapp-production
    heroku-postgresql (postgresql-prod-123)  standard-0  $50/month
     └─ as DATABASE
    

    2. Then attach the production database add-on to your staging app. Give it a name like PRODUCTION_DB to make it easy to recognize:

    $ heroku addons:attach postgresql-prod-123 --app myapp-staging --as PRODUCTION_DB
    

    3. Then create a fork of the production database on the staging app:

    $ heroku addons:create heroku-postgresql:standard-0 --fork PRODUCTION_DB_URL --as STAGING_DB --app myapp-staging
    

    4. Finally promote the fork to be the primary database of your staging app:

    $ heroku pg:promote STAGING_DB --app myapp-staging
    

    Done! Your staging app is now using a copy of your production database. Note that your previous staging database is still there, you may want to destroy it after you've made sure everything works.

    To clean up, detach the production database from the staging app:

    $ heroku addons:detach postgresql-prod-123 --app myapp-staging
    
    0 讨论(0)
  • 2021-01-30 03:45

    I think its not --remote its --app try this:

    heroku pgbackups:restore DATABASE `heroku pgbackups:url --app production-app` --app staging-app
    
    0 讨论(0)
  • 2021-01-30 03:46

    UPDATE: This no longer works. Please refer to @lucas-nelson's answer below.

    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/upgrade-heroku-postgres-with-pgbackups#transfering-databases-between-heroku-applications

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

    0 讨论(0)
  • 2021-01-30 03:46

    This is what worked for me

    • Download the backup from heroku console and uploaded it to s3.
    • heroku pg:backups restore 'DUMP_FILE_URL_FROM_S3' DATABASE --app MY_APP
    0 讨论(0)
  • 2021-01-30 03:53

    You can do this using below command

    heroku pg:copy <production_app_name>::HEROKU_POSTGRESQL_BLACK_URL OLIVE -a <staging_app_name> --confirm <staging_app_name>
    
    0 讨论(0)
  • 2021-01-30 03:56

    I was struggling with the same issue. According to the answer to this question, the problem could be your heroku gem version. I just upgraded my version (from 2.26.2 to 2.26.6) and now it works.

    0 讨论(0)
提交回复
热议问题