added restore staging db script
This commit is contained in:
parent
32e831299b
commit
9eb116502a
48
restore-staging-db-with-production.sh
Executable file
48
restore-staging-db-with-production.sh
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
function indent() {
|
||||||
|
sed 's/^/ /';
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_maintenance() {
|
||||||
|
# app_name mode
|
||||||
|
heroku maintenance:$2 --app $1
|
||||||
|
}
|
||||||
|
|
||||||
|
function scale_down() {
|
||||||
|
# app_name
|
||||||
|
heroku ps --app $1 | grep === | while read line ; do
|
||||||
|
name=$( echo "$line" |cut -d ' ' -f2 )
|
||||||
|
heroku ps:scale $name=0 --app $1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function copy_db {
|
||||||
|
# from_app, from_db, to_app, to_db
|
||||||
|
# heroku pg:copy $1::$2 $4 --app $3 --confirm $3 # this is too slow
|
||||||
|
heroku pg:backups capture $2 --app $1 # capture backup # not required if we want to use the latest backup
|
||||||
|
backup_id=`heroku pg:backups --app $1 | grep $2 | head -n1 | cut -d " " -f 1`
|
||||||
|
echo " RESTORING BACKUP ID $backup_id ($1/$2) to $3/$4"
|
||||||
|
heroku pg:backups restore "`heroku pg:backups public-url $backup_id --app $1`" $4 --app $3 --confirm $3 # restore backup
|
||||||
|
}
|
||||||
|
|
||||||
|
function scale_web_dyno_to_one() {
|
||||||
|
# app_name
|
||||||
|
heroku ps:scale web=1 --app $1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo -e "\n*** ENABLING MAINTENANCE MODE ***"
|
||||||
|
set_maintenance qrtr-services-staging on
|
||||||
|
|
||||||
|
echo -e "\n*** TURN OFF DYNOS ***"
|
||||||
|
scale_down qrtr-services-staging
|
||||||
|
|
||||||
|
echo -e "\n*** EMPTYING DB ***"
|
||||||
|
heroku pg:reset DATABASE --app qrtr-services-staging --confirm qrtr-services-staging
|
||||||
|
|
||||||
|
echo -e "\n*** RESTORING DB ***"
|
||||||
|
copy_db qrtr-services DATABASE qrtr-services-staging DATABASE | indent
|
||||||
|
|
||||||
|
echo -e "\n*** TURN ON WEB DYNOS ***"
|
||||||
|
scale_web_dyno_to_one qrtr-services-staging
|
||||||
|
|
||||||
|
echo -e "\n*** DISABLING MAINTENANCE MODE ***"
|
||||||
|
set_maintenance qrtr-services-staging off
|
||||||
Loading…
Reference in New Issue
Block a user