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