Mercurial > public > ssdt-docker
annotate scripts/restore-inventory.sh @ 484:237618ae3f10
USASR-5154 revert
author | belknapSSDT <zach.belknap@mcoecn.org> |
---|---|
date | Thu, 28 Sep 2023 16:33:14 -0400 |
parents | b3909bd1a2b6 |
children |
rev | line source |
---|---|
395
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
1 #!/bin/bash |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
2 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
3 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
4 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
5 sourceFile=${1?must provide backup file to be restored} |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
6 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
7 if [ -z "$1" ] |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
8 then |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
9 echo "Usage: `basename $0` {backup file to restore}" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.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:" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
11 echo " {IRN}{entityId}-inventory-db.{timestamp}.backup.gz " |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
12 exit $E_NOARGS |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
13 fi |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
14 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
15 function prop { |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
16 grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
17 } |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
18 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
19 entityId=$(prop 'entityId' | tr -d '"') |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
20 dbContainerName="$entityId-inventory-db" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
21 appContainerName="$entityId-inventory-app" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
22 target="invdb" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
23 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
24 echo |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
25 echo "Preparing to restore" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
26 echo "--------------------" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
27 echo " file: $sourceFile" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
28 echo " to $dbContainerName database: $target" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
29 echo " " |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
30 echo "WARNING: This operation will DELETE and replace any exising database" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
31 echo " " |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
32 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
33 read -e -p "Continue? <y/N> " answer |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
34 case $answer in |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
35 y | Y | yes | YES ) answer="y";; |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
36 n | N | no | NO ) answer="n";; |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
37 *) answer="n" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
38 esac |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
39 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
40 if [ "$answer" == "y" ] |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
41 then |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
42 echo "stopping application service $appContainerName" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
43 docker stop $appContainerName |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
44 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
45 echo "copy backup file to database container" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
46 docker cp ${sourceFile} ${dbContainerName}:/tmp/restore.backup.gz |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
47 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
48 echo "starting database restore" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.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" |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
50 |
b3909bd1a2b6
INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff
changeset
|
51 fi |