comparison scripts/restore-workflow.sh @ 396:639c933cefee

INV-198 create restore-workflows.sh script
author Matt Calmes <calmes@ssdt-ohio.org>
date Thu, 28 Oct 2021 06:09:44 -0400
parents
children
comparison
equal deleted inserted replaced
395:b3909bd1a2b6 396:639c933cefee
1 #!/bin/bash
2
3 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
4
5 sourceFile=${1?must provide backup file to be restored}
6
7 if [ -z "$1" ]
8 then
9 echo "Usage: `basename $0` {backup file to restore}"
10 echo " must specify the name of the file to restore. Assumed to be in format:"
11 echo " {entityId}-workflows-db.{timestamp}.backup.gz "
12 exit $E_NOARGS
13 fi
14
15 function prop {
16 grep "${1}" .env/ssdt-workflows-shared.properties|cut -d'=' -f2
17 }
18
19 entityId=$(prop 'entityId' | tr -d '"')
20 dbContainerName="$entityId-workflows-db"
21 appContainerName="$entityId-workflows-app"
22 target="workflowsdb"
23
24 echo
25 echo "Preparing to restore"
26 echo "--------------------"
27 echo " file: $sourceFile"
28 echo " to $dbContainerName database: $target"
29 echo " "
30 echo "WARNING: This operation will DELETE and replace any exising database"
31 echo " "
32
33 read -e -p "Continue? <y/N> " answer
34 case $answer in
35 y | Y | yes | YES ) answer="y";;
36 n | N | no | NO ) answer="n";;
37 *) answer="n"
38 esac
39
40 if [ "$answer" == "y" ]
41 then
42 echo "stopping application service $appContainerName"
43 docker stop $appContainerName
44
45 echo "copy backup file to database container"
46 docker cp ${sourceFile} ${dbContainerName}:/tmp/restore.backup.gz
47
48 echo "starting database restore"
49 docker exec -t -u postgres $dbContainerName sh -c "gunzip -f /tmp/restore.backup.gz -c | psql"
50
51 fi