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