Heroku transfer db from one app to another

后端 未结 8 1962
攒了一身酷
攒了一身酷 2021-01-31 02:25

I need to transfer db from app_1 to app_2

I created backup on app_1

Then ran:

heroku pg:backups restore HEROKU_POSTGRESQL_COLOR --app app_2 heroku

8条回答
  •  庸人自扰
    2021-01-31 02:54

    If you look at heroku docs it says

    PG Backups as an add-on has been deprecated. The commands exist as part of the Heroku Postgres namespace in the CLI. The new functionality is live and available for use.

    So you can use the pgbackups functionality directly without having to add any add-ons

    To create a backup you can run

     heroku pg:backups capture --app app_name
    

    if you have multiple databases then you can specify database url like this

    heroku pg:backups capture HEROKU_POSTGRESQL_PINK
    

    To restore from a backup on another app you can run

    heroku pg:backups restore b001 DATABASE_URL --app app_name
    

    You can transfer database by

    heroku pg:copy DATABASE_URL HEROKU_POSTGRESQL_PINK_URL --app app_name
    

    You can also upload your database to a public url and then use that url to import database on another app by

    heroku pg:backups public-url b001 --app app_name
    

    and then import it by

    heroku pg:backups restore 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump' DATABASE -a app_name
    

    If you are moving from one app to another and want to use same database for another app then you can follow these steps:

    • Login to your heroku account
    • Select your old app and go to settings tab
    • Reveal config vars for your old app
    • Copy DATABASE_URL
    • Go back and select your new app
    • Replace new apps DATABASE_URL with the old apps value

提交回复
热议问题