Heroku transfer db from one app to another

后端 未结 8 1844
攒了一身酷
攒了一身酷 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:53

    its only 1 command to copy database from app to app now you don't have to backup:

    heroku pg:copy app_name_to_copy_from::database_color_to_copy_from database_color_to_copy_to --app app_name_to_copy_to
    

    check it here

    0 讨论(0)
  • 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
    0 讨论(0)
  • 2021-01-31 03:00

    As per the website the addon is depreciated. So that could be the reason for the failure message.

    Backups as an add-on has been deprecated.

    Since your aim is to move the db from one app to another, why don't you try the instructions mentioned in the link below.

    https://devcenter.heroku.com/articles/heroku-postgres-backups#direct-database-to-database-copies

    0 讨论(0)
  • 2021-01-31 03:03
    heroku pg:copy app1_name::HEROKU_POSTGRESQL_ONYX_URL HEROKU_POSTGRESQL_AQUA_URL --app app2_name
    

    Where the second db url is on app2_name

    0 讨论(0)
  • 2021-01-31 03:05

    I had a related issue. You can save a backup to your local machine, then upload it to some hosting, like amazon s3, and import from given url. This question and following answer may help you: Can't import to heroku postgres database from dump

    0 讨论(0)
  • 2021-01-31 03:12

    I found the simpler solution to reuse/share the same resource (postgres database in this case - or any others that allow sharing/reuse) with more than one app on heroku is doing the following:

    1. Go to the older (source) app dashboard on Heroku
    2. Select the "Resources" tab
    3. Locate the resource (postgres database, in our case here)
    4. Click on the icon next to the plan name at the right most part of the row listing the resource
    5. Select the "Attach to another app" option and select the newer (target) app name from the list that shows up

    Sample of the extended menu mentioned @ step #4 above!

    That's all it takes to share the resource between the apps as it automatically updates all the related configuration settings on the target app. This comes handy since none of the add-on related configuration variables are directly editable, at least from the dashboard (have not checked through the CLI). Hope this helps anyone looking for similar thing.

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