Last active
August 2, 2016 06:53
-
-
Save brain90/df5d815ea74932641144 to your computer and use it in GitHub Desktop.
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/bash | |
set -x | |
echo 'Processing...' | |
# Script ini dijalankan dari staging server | |
# Dump latest db di Production | |
ssh brain@bojong-production -v <<'ENDSSH' pg_dump -Fc -U knuth -N sym -T sym* -h 192.168.3.1 spacex_production -p 5433 > | |
$(date +"%Y%m%d")_spacex_production.backup --verbose | |
ENDSSH | |
# Tarik latest db ke Staging | |
scp brain@bojong-production:~/$(date +"%Y%m%d")_spacex_production.backup . | |
# Siapkan database baru untuk proses debug di Staging | |
psql -U knuth -h dev spacex_staging -p 5433 -c 'create database spacex_production_'$(date+"%Y%m%d") | |
# Install tablefunc extension (ada beberapa fitur view yang menggunakan pivot ) | |
psql -U knuth -h dev spacex_production'_'$(date +"%Y%m%d") -p 5433 -c 'create extension tablefunc;' | |
# Restore latest db ke @staging | |
pg_restore -U knuth -h dev -p 5433 -d spacex_production'_'$(date +"%Y%m%d") < $(date +"%Y%m%d")_spacex_production.backup --verbose | |
# Ubah database name pada string dsn di konfigurasi apps. | |
grep -r -l "spacex_staging" lib/ | xargs sed -i 's/spacex_staging/spacex_production'_'$(date +"%Y%m%d")/g' | |
# Done | |
echo 'END.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment