changeset 229:6210629ba54f production v1.7.0

flow: Merged <release> 'v1.7.0' to <master> ('production').
author smith@nwoca.org
date Mon, 09 Oct 2017 21:35:35 +0100
parents fe6e83ff2d12 (current diff) 0add40f5c5b7 (diff)
children 195d46a689d4
files scripts/restore-usas.sh scripts/restore-usps.sh
diffstat 3 files changed, 59 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/restore-container.sh	Mon Oct 09 21:35:35 2017 +0100
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
+
+sourceFile=${1?must provide backup file to be restored}
+
+if [ -z "$1" ]
+then
+  echo "Usage: `basename $0` {backup file to restore}"
+  echo " must specify the name of the file to restore.  Assumed to be in format:"
+  echo "     {service}.{timestamp}.backup.gz  "
+  echo "       where {service} is the usasdb or uspsdb container to be restored."
+  echo " The script will restore the backup to the appropriate container based "
+  echo " on the filename."
+  exit $E_NOARGS
+fi
+
+target=$(basename $1)
+target=${target%%.*}
+
+project=$(composeGetProject $target)
+
+if [ "$project" == "" ]; then
+   echo "no project available"
+   exit 1
+fi
+
+echo 
+echo "Preparing to restore"
+echo "--------------------"
+echo "   file: $sourceFile"
+echo "   to    ${project}/${target} database: $target"
+echo " "
+echo "WARNING:  This operation will DELETE and replace any exising database"
+echo " "
+
+read -e -p "Continue? <y/N> " answer
+case $answer in
+     y | Y | yes | YES ) answer="y";;
+     n | N | no | NO ) answer="n";;
+     *) answer="n"
+esac
+
+if [ "$answer" == "y" ] 
+then
+  appService=${target/db/app}
+  echo "stopping application service $appService"
+  docker-compose stop $appService
+
+  dbContainer=$(composeGetContainer $target)
+ 
+  echo "copy backup file to database container"
+  docker cp ${sourceFile} ${dbContainer}:/tmp/restore.backup.gz
+
+  echo "starting database restore"
+  docker-compose exec -T -u postgres $target sh -c "gunzip -f /tmp/restore.backup.gz -c | psql"
+
+fi
+
--- a/scripts/restore-usas.sh	Mon Oct 09 17:23:09 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-if [ -z "$1" ]
-then
-  echo "Usage: `basename $0` {backup file to restore}"
-  echo  " filename must relative to the container's file system. (e.g. /backup/filename)"
-  exit $E_NOARGS
-fi
-
-source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
-
-docker-compose stop usasapp
-docker-compose restart usasdb
-docker-compose run --rm usasdb sh -c \
-   "gunzip -f $1 -c | psql --host=usasdb --username=postgres"
-docker-compose start usasapp
--- a/scripts/restore-usps.sh	Mon Oct 09 17:23:09 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#!/bin/bash
-if [ -z "$1" ]
-then
-  echo "Usage: `basename $0` {backup file to restore}"
-  echo  " filename must relative to the container's file system. (e.g. /backup/filename)"
-  exit $E_NOARGS
-fi
-source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
-
-docker-compose stop uspsapp
-docker-compose restart uspsdb
-docker-compose run --rm uspsdb sh -c \
-   "gunzip -f $1 -c | psql --host=uspsdb --username=postgres"
-docker-compose start uspsapp
-