Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku app change: db migration (pg and MongoHQ)

Tags:

heroku

mongohq

I had and app on heroku then I decided to create another app (on cedar stack which does not support stack:migrate).

How can I migrate databases PG and MongoHq?

Thanks!

like image 507
WHITECOLOR Avatar asked Nov 26 '11 11:11

WHITECOLOR


2 Answers

You can migrate MongoHQ by logging into heroku and clicking on addons => mongohq. From the application, create a new user under Database Users named "backup" with a simple password. Below, my password was "temppw". Then click the Database Info tab for your connection information (host:port [flame.mongohq.com:27049] and dbname [appXXXXXX]). Then just call mongodump to get a backup.

mongodump -h flame.mongohq.com:27049 -d appXXXXXX -u backup -p temppw

This will make a local directory called "dump" containing your data. Verify it is there by loading it into a local db (just run mongorestore and look in your local mongo install) - because when you destroy your old app, it destroys the MongoDB (heroku also destroys your postgres db - so you should do this for that as well).

Anyway, do the same as above to your new application database, except use mongorestore.

mongorestore -h flame.mongohq.com:27049 -d appXXXXXX -u backup -p temppw dump/appXXXXXX

DO NOT JUST POINT THE ENVIRONMENT URLS. This is dangerous, because deleting your initial app will destroy all of your data.

like image 150
Coderoshi Avatar answered Oct 10 '22 03:10

Coderoshi


I'm not sure about MongoHQ but as for PostgreSQL, you can use Heroku Taps to pull the data from the remote database to your local machine. You could then push it to the new app.

Alternatively you could change the environment variable DATABASE_URL of your new Cedar app to point to the database being used by the old app - assuming you're not using the shared database.

This last approach would also work for MongoHq.

like image 24
leonardoborges Avatar answered Oct 10 '22 05:10

leonardoborges