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

后端 未结 12 2165
刺人心
刺人心 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:30

    First create an up to date backup of production:

    heroku pgbackups:capture -a productionappslug --expire
    

    Find out what colour Heroku has named your database.

    https://postgres.heroku.com/databases or https://dashboard.heroku.com/apps/STAGINGAPPSLUG/resources

    Then load the production db backup into staging (changing RED to whatever colour yours is):

    heroku pgbackups:restore HEROKU_POSTGRESQL_RED -a stagingappslug `heroku pgbackups:url -a productionappslug`
    

    stagingappslug and liveappslug are whatever shortnames your heroku apps are called.

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

    UPDATE: You can run this command to transfer the database from production to staging: heroku pg:copy your-app::DATABASE_URL DATABASE_URL -a yourapp-staging

    It will prompt you to confirm the action, and once you have done that, all of the data will be migrated.

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

    To transfer (copy) the production database (source database) to the staging database (target database) you will need to invoke pg:copy from the target application, referencing a source database.

    heroku pg:copy source-application::OLIVE HEROKU_POSTGRESQL_PINK -a target-application

    Another example:

    heroku pg:copy my-production-app::HEROKU_POSTGRESQL_OLIVE HEROKU_POSTGRESQL_PINK --app my-staging-app

    To obtain the colour names of your databases, use:

    heroku pg --app my-production-app
    heroku pg --app my-staging-app
    

    See pg:copy

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

    After NO LUCK. (Im using heroku gem 2.31.4) I did the following (help for the weary)

    1. Login into Heroku Database console

    2. Login to staging > 'settings' > PGRestore > Copy 'Connection Settings' into a text file.

    3. Login to production > Snapshots, press '+' to make a new backup as of now. Then press download. Download into the apps /tmp folder or whever you want.

    4. Set staging to maintenance mode

      $ heroku maintenance:on

    5. Run the command like so, with Connection Settings text and dump file at the end: PGPASSWORD={...bits of stuff here...} -p 5432 'tmp/b048.dump.dump'

    6. After run:

      $ heroku maintenance:off

    7. Login to staging and check that things match. Find a recent transaction you know is in production if you can via. $ heroku run console for both apps and check ids match.

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

    This works for me: heroku pg:copy you-app-production::DATABASE DATABASE -a you-app-staging

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

    Update for mid-2017 (stealing from Takehiro Mouri's answer - simplify the DATABSE_NAME part)

    Update for mid-2015...

    The pgbackups add-on has been deprecated. No more pgbackups:transfer.

    To copy a database from yourapp to yourapp_staging:

    # turn off the web dynos in staging
    heroku maintenance:on -a yourapp-staging
    
    # if you have non-web-dynos, do them too
    heroku ps:scale worker=0 -a yourapp-staging
    
    # backup the staging database if you are paranoid like me (optional)
    heroku pg:backups capture -a yourapp-staging
    
    # execute the copy
    heroku pg:copy your-app::DATABASE_URL DATABASE_URL -a yourapp-staging
    

    Then when it's complete, turn staging back on:

    # this is if you have workers, change '1' to whatever
    heroku ps:scale worker=1 -a yourapp-staging
    
    heroku maintenance:off -a yourapp-staging
    

    (source: https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases#upgrade-with-pg-copy-default)

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