comparison scripts/restore-ess.sh @ 528:e483148f5283

Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
author Marc Davis <marc.davis@mcoecn.org>
date Tue, 23 Apr 2024 14:47:12 -0400
parents
children 6f7ae8d659cf
comparison
equal deleted inserted replaced
527:4b026170dfea 528:e483148f5283
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}-ess-db.{timestamp}.backup.gz "
12 exit $E_NOARGS
13 fi
14
15 function prop {
16 grep "${1}" .env/ess-shared.properties|cut -d'=' -f2
17 }
18
19 entityId=$(prop 'entityId' | tr -d '"')
20 dbContainerName="$entityId-ess-db"
21 appContainerName="$entityId-ess-app"
22 target="essdb"
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