Skip to content

Instantly share code, notes, and snippets.

@stevenharman
Created September 10, 2013 21:37
Show Gist options
  • Save stevenharman/6516090 to your computer and use it in GitHub Desktop.
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).
#!/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