27 Mar Export and Import database from local to heroku
Export and import from local to heroku
From local run the following command replacing with your own values
1 | pg_dump --no-owner --no-acl -d db /padroncolima_development > yourdatabasedump |
Upload this file “yourdatabasedump” into a public repository like S3( if that is the case dont forget to set public permissions to the file).
Now backups are part of heroku.com and they stop using this pg backup as an add-on the new command you have to run look something similar to this:
1 | heroku pg:backups restore 'https://s3.amazonaws.com/spreedemostore/yourdatabasedump' DATABASE -a pco. |
If you have problems with your sql import you have an alternative:
First thing: generate your sql in local:
1 2 3 | pg_dump -d db /your_db_name_development > test2.sql # or without owner and acl pg_dump --no-owner --no-acl -d db /your_db_name_development > test2.sql |
And then import the sql into heroku
1 | cat test2.sql | heroku pg:psql --app your_app_name_goes_here |
Generate a downloadable dump from Heroku
1 2 3 4 5 | # generate a new dump of your database heroku pg:backups capture --app=yourappname # this will download the last generated dump heroku pg:backups public-url --app=yourappname # and then just visit the generated url |
Some commands you might find useful:
If you are using s3cmd to upload your file into amazon aws:
1 | s3cmd put yourdatabasedump s3: //yourbucket/yourdatabasedump --acl-public |
If you want to import that in local development:
1 | psql -d db /yourdb_goes_here < your-dump- file |
Check which posgress plan your application has
1 | heroku addons | grep POSTGRES |
If you are using the free postgress plain and you want to pay for example the basic $9 per month you can upgrade your plan like so:
1 | heroku addons:add heroku-postgresql:hobby-basic |
Set a different database url for your heroku app
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Create a new database heroku addons:add heroku-postgresql:hobby-basic # see the current databse used heroku config # you are going to see something like: # DATABASE_URL: postgres://dfl3IwE6hHj2qsqQNGVaackrK0@ec2-54-163-227-57.compute-1.amazonaws.com:5432/xxxxfd # HEROKU_POSTGRESQL_ROSE_URL: postgres://dfl3IwE6hHj2qsqQNGVaackrK0@ec2-54-163-227-57.compute-1.amazonaws.com:5432/xxxxfd # HEROKU_POSTGRESQL_TEAL_URL: postgres://dfl3IwE6hH2qsqQNGVaackrK0@ec2-54-163-227-57.compute-1.amazonaws.com:5432/xxxxxxxfde # LANG: en_US.UTF-8 # now you can set a new url using the command: heroku set VARIABLE=value # in my case heroku config: set DATABASE_URL=postgres: //dfl3IwE6hH2qsqQNGVaackrK0 @ec2-54-163-227-57.compute-1.amazonaws.com:5432 /xxxxxxxfde |
Override your current database in heroku with a new dump or sql file
1 2 3 4 5 | # reset and empty your database in heroku heroku pg:reset DATABASE # Now import your sql see the commands above # migrate your database heroku run rake db:migrate |
Import dump downloaded from heroku into local
1 2 3 | pg_dump --no-owner --no-acl -d db/yourdb_development < TEAL_553ed6ff69702d796a160000.dump # or try pg_restore --verbose --clean --no-acl --no-owner -d db/yourdb_development TEAL_553ed6ff69702d796a160000.dump |
No Comments