Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku transfer db from one app to another

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 pgbackups:url --app app_1

HEROKU_POSTGRESQL_COLOR = database URL for app_2

Then I get:

 !    `pg:backups` is not a heroku command.
 !    Perhaps you meant `pgbackups`.
 !    See `heroku help` for a list of available commands.

So I ran:

heroku pgbackups:restore HEROKU_POSTGRESQL_COLOR --app app_2 heroku pgbackups:url --app app_1

Then I get the following:

!    WARNING: Destructive Action
!    This command will affect the app: app_2
!    To proceed, type "app_2" or re-run this command with --confirm app_2

So I confirmed with:

> app_2
 !    Please add the pgbackups addon first via:
 !    heroku addons:add pgbackups

So then I ran: heroku addons:add pgbackups --app app_2

Adding pgbackups on app_2... failed
 !    Add-on plan not found.

Is there a way around this issue? any help would be greatly appreciated!

* Solution *

I ended up emailing Heroku, they advised that I need to heroku update; heroku plugins:update but heroku update is only available to heroku toolbelt only and I had the gem installed.

Solution:

Install Heroku toolbelt here

Then uninstall the gem:

gem uninstall heroku --all

run the following to get the version and it should output heroku-toolbelt, instead of the gem, more info here

$ heroku --version
  heroku-toolbelt/2.39.0 (x86_64-darwin10.8.0) ruby/1.9.3

To copy the databases over:

heroku pg:backups restore `heroku pgbackups:url --app app_1` HEROKU_POSTGRESQL_COLOR --app app_2

But even better—you can copy directly from one database to another without needing the backup:

Assuming app_2 database url is: HEROKU_POSTGRESQL_GOLD

heroku pg:copy app_1::DATABASE_URL GOLD -a app_2 

That will copy the main database from app_1 to the GOLd database on app_2

like image 607
neo Avatar asked Apr 20 '15 16:04

neo


People also ask

How do I transfer my Heroku app?

In Dashboard, click the Team name of the Team you would like to transfer apps into. Click the Transfer apps button. Use the select box to select apps from your personal apps list, or another Team's apps list. Select the apps you would like to transfer to the Team.

Does Heroku save database?

Heroku Postgres delivers the world's most advanced open source database as a trusted, secure, and scalable service that is optimized for developers.


4 Answers

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

like image 81
mohamed-ibrahim Avatar answered Oct 14 '22 09:10

mohamed-ibrahim


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
like image 27
Mandeep Avatar answered Oct 14 '22 10:10

Mandeep


I needed something slightly different so sharing it here:

heroku pg:copy name_of_app_being_copied::DATABASE_URL DATABASE_URL --app name_of_app_being_copied_to

Note: Both references to DATABASE_URL do not need to be changed. It may seem odd, but the first instance references the database url for the app being copied and the second one references the database url of the app being copied to.

like image 37
Kyle Krzeski Avatar answered Oct 14 '22 10:10

Kyle Krzeski


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

like image 34
pixelearth Avatar answered Oct 14 '22 11:10

pixelearth