Created
September 10, 2013 21:37
-
-
Save stevenharman/6516090 to your computer and use it in GitHub Desktop.
Backup one Heroku Postgres database and restore it to another. This is particularly useful for restoring production data to a staging DB (running on a Dev/Basic plan).
This file contains 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
#!/bin/sh | |
set -e | |
app=${1} | |
staging_app=staging-${app} | |
staging_db=`heroku config -a ${staging_app} | grep ^HEROKU_POSTGRESQL | cut -d : -f 1 | sed s/_URL//` | |
# Create a production backup on Heroku | |
heroku pgbackups:capture --expire --app ${app} | |
# Restore production's backup to the staging app | |
heroku pgbackups:restore ${staging_db} -a ${staging_app} `heroku pgbackups:url -a ${app}` --confirm ${staging_app} | |
set +e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment