Created
December 7, 2012 17:35
-
-
Save dpmccabe/4234945 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| production_app_name="getafive" | |
| pg_dev_db="gaf_development" | |
| function LastBackupName() { | |
| heroku pgbackups --app="$production_app_name" | grep '(DATABASE_URL)' | tail -n 1 | cut -d " " -f 1 | |
| } | |
| # delete last manual backup and create new one | |
| old_backup=$(LastBackupName) | |
| heroku pgbackups:destroy $old_backup --app="$production_app_name" | |
| heroku pgbackups:capture --app="$production_app_name" | |
| new_backup=$(LastBackupName) | |
| # terminate local pg connections | |
| echo "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid()" | psql postgres | |
| # recreate empty db | |
| rake db:drop --trace | |
| rake db:create --trace | |
| # download remote pg dump and restore to local db | |
| curl $(heroku pgbackups:url $new_backup --app="$production_app_name") > $(dirname $0)/tmp/pg_backup.dump | |
| pg_restore --verbose --clean --no-acl --no-owner -h localhost -d $pg_dev_db $(dirname $0)/tmp/pg_backup.dump | |
| rm -f pg_backup.dump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment