annotate scripts/restore-ess.sh @ 531:9f618d578e10 release/2.17.0

flow: Closed <release> '2.17.0'.
author Marc Davis <marc.davis@mcoecn.org>
date Thu, 02 May 2024 22:46:15 -0400
parents e483148f5283
children 6f7ae8d659cf
rev   line source
528
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
1 #!/bin/bash
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
2
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
3 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
4
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
5 sourceFile=${1?must provide backup file to be restored}
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
6
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
7 if [ -z "$1" ]
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
8 then
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
9 echo "Usage: `basename $0` {backup file to restore}"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
10 echo " must specify the name of the file to restore. Assumed to be in format:"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
11 echo " {entityId}-ess-db.{timestamp}.backup.gz "
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
12 exit $E_NOARGS
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
13 fi
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
14
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
15 function prop {
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
16 grep "${1}" .env/ess-shared.properties|cut -d'=' -f2
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
17 }
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
18
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
19 entityId=$(prop 'entityId' | tr -d '"')
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
20 dbContainerName="$entityId-ess-db"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
21 appContainerName="$entityId-ess-app"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
22 target="essdb"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
23
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
24 echo
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
25 echo "Preparing to restore"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
26 echo "--------------------"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
27 echo " file: $sourceFile"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
28 echo " to $dbContainerName database: $target"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
29 echo " "
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
30 echo "WARNING: This operation will DELETE and replace any exising database"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
31 echo " "
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
32
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
33 read -e -p "Continue? <y/N> " answer
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
34 case $answer in
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
35 y | Y | yes | YES ) answer="y";;
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
36 n | N | no | NO ) answer="n";;
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
37 *) answer="n"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
38 esac
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
39
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
40 if [ "$answer" == "y" ]
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
41 then
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
42 echo "stopping application service $appContainerName"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
43 docker stop $appContainerName
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
44
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
45 echo "copy backup file to database container"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
46 docker cp ${sourceFile} ${dbContainerName}:/tmp/restore.backup.gz
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
47
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
48 echo "starting database restore"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
49 docker exec -t -u postgres $dbContainerName sh -c "gunzip -f /tmp/restore.backup.gz -c | psql"
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
50
e483148f5283 Add backup, restore, and update ess scripts. Handle ess in workflows update and remove container stop/removal from install ess script.
Marc Davis <marc.davis@mcoecn.org>
parents:
diff changeset
51 fi