Created
February 14, 2014 10:37
-
-
Save gma/8999026 to your computer and use it in GitHub Desktop.
Copy production backup to staging (Heroku)
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
#!/bin/bash | |
PRODUCTION_REMOTE="production" | |
STAGING_REMOTE="staging" | |
STAGING_DATABASE_NAME="HEROKU_POSTGRESQL_COBALT" | |
## Functions | |
reset_staging_database() | |
{ | |
heroku pg:reset $STAGING_DATABASE_NAME -r $STAGING_REMOTE | |
} | |
latest_backup() | |
{ | |
heroku pgbackups -r $PRODUCTION_REMOTE | tail -n 1 | cut -f 1 -d ' ' | |
} | |
latest_backup_url() | |
{ | |
heroku pgbackups:url $(latest_backup) -r $PRODUCTION_REMOTE | |
} | |
restore_production_to_staging() | |
{ | |
local url="$(latest_backup_url)" | |
heroku pgbackups:restore $STAGING_DATABASE_NAME "$url" -r $STAGING_REMOTE | |
} | |
## Main program | |
set -x | |
reset_staging_database | |
restore_production_to_staging |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment