From 6ed4c610410903d30361029a8538862571370801 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Thu, 14 May 2015 02:03:15 +0200 Subject: [PATCH] Deploy skript a zaloha DB pred kazdym updatem --- Makefile | 27 +++++++++++++++++++++++++-- backup_prod_db.sh | 10 ++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 backup_prod_db.sh diff --git a/Makefile b/Makefile index a5cc9e93..62bb504e 100644 --- a/Makefile +++ b/Makefile @@ -58,13 +58,18 @@ schema_seminar.pdf: schema_all.pdf: ./manage.py graph_models -a -g | dot -Tpdf > schema_all.pdf +# remote commands TEST_USER=test-mam TEST_SERVER=atrey.karlin.mff.cuni.cz TEST_DIR=/home/test-mam/mamweb-test/ -# remote commands +PROD_USER=test-mam +PROD_SERVER=atrey.karlin.mff.cuni.cz +PROD_DIR=/home/test-mam/mamweb-prod/ + HEAD=`git log --color=never |head -1|sed 's/.*commit //'` + push_test: @echo "Checking out commited HEAD (${HEAD}) state at ${TEST_SSH} ..." git push --all @@ -80,6 +85,24 @@ push_test: (chown -Rf :mam . || true ) && \ (chmod -Rf g+w . || true ) && \ echo Done." - @echo "Test deployed at ${TEST_SERVER}:${TEST_DIR} successfully." + @echo "Test pushed to ${TEST_SERVER}:${TEST_DIR} successfully." + +push_prod: + @echo "Checking out commited HEAD (${HEAD}) state at ${PROD_SSH} ..." + git push --all + ssh ${PROD_USER}@${PROD_SERVER} -n -x "\ + cd ${PROD_DIR} && \ + ./backup_prod_db.sh && \ + git fetch --all && \ + git checkout ${HEAD} -f && \ + git clean -f && \ + cp mamweb/settings_prod.py mamweb/settings.py && \ + make install && \ + ./manage.py collectstatic --noinput && \ + ./manage.py migrate --noinput && \ + (chown -Rf :mam . || true ) && \ + (chmod -Rf g+w . || true ) && \ + echo Done." + @echo "Deployed to ${PROD_SERVER}:${PROD_DIR} successfully." diff --git a/backup_prod_db.sh b/backup_prod_db.sh new file mode 100755 index 00000000..99bc5429 --- /dev/null +++ b/backup_prod_db.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +DBNAME=mam +FNAME=backup-db/$DBNAME-prod-`date '+%F-%T'`.bz2 +echo Backing up production DB $DBNAME to $FNAME ... + +pg_dump $DBNAME | bzip2 -9 > $FNAME + +echo Done. +