Reputation: 248
We have a production database, and we'd like to take regular snapshots of it to our staging database.
I know how to do this using pgbackups, I was wondering if anyone knows how to do it with the new HerokuPostgres fork function.
Upvotes: 5
Views: 865
Reputation: 7691
Adding to Craig's answer, here's a script by freeformz which does the whole job.
app=${1}
db_type=${2:-ronin}
old_db=`heroku config -a ${app}-staging | grep ^HEROKU_POSTGRESQL | cut -d : -f 1 | sed s/_URL//`
heroku addons:add heroku-postgresql:${db_type} --fork `heroku config -a ${app} | grep ^DATABASE_URL | cut -d : -f 2-5` -a ${app}-staging
new_db=`heroku config -a ${app}-staging | grep ^HEROKU_POSTGRESQL | grep -v ${old_db} | cut -d : -f 1 | sed s/_URL//`
heroku pg:wait -a ${app}-staging
heroku pg:promote ${new_db} -a ${app}-staging
#Remove the old db
if [ ! -z "${old_db}" ]l; then
heroku addons:remove ${old_db} -a ${app}-staging --confirm ${app}-staging
fi
Upvotes: 3
Reputation: 5979
Yes, you can create a fork from directly from one applications DB to another. To do this get the value for your DATABASE_URL from your primary application then use it in the below command:
heroku addons:add heroku-postgresql:ronin --fork postgres://username:password@ec2.../database --app yourstagingapp
Upvotes: 7