Gih's Blog

只言片语

backup/export database from heroku

2015-04-27 by gihnius, tagged as database

escape from heroku

app="gallery"

backup db of app

heroku pgbackups:capture -a $app-staging
heroku pgbackups:capture -a $app-demo
heroku pgbackups:capture -a $app-production

download

curl -o staging.dump `heroku pgbackups:url -a $app-staging`
curl -o demo.dump `heroku pgbackups:url -a $app-demo`
curl -o prod.dump `heroku pgbackups:url -a $app-production`

upload to ec2

scp *.dump admin@EC2IP:

import db

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U rails -d $app_dev staging.dump
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U rails -d $app_demo demo.dump
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U rails -d $app_production prod.dump

refer

https://devcenter.heroku.com/articles/pgbackups