Mercurial > public > ssdt-docker
comparison scripts/restore-itcm.sh @ 409:c059e112e719
move files
author | Marc Davis <marc.davis@mcoecn.org> |
---|---|
date | Wed, 12 Oct 2022 19:13:38 -0400 |
parents | prod/restore-itcm.sh@e49038cbb14c |
children | 6f7ae8d659cf |
comparison
equal
deleted
inserted
replaced
408:e49038cbb14c | 409:c059e112e719 |
---|---|
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}-itcm-db.{timestamp}.backup.gz " | |
12 exit $E_NOARGS | |
13 fi | |
14 | |
15 function prop { | |
16 grep "${1}" .env/itcm-shared.properties|cut -d'=' -f2 | |
17 } | |
18 | |
19 entityId=$(prop 'entityId' | tr -d '"') | |
20 dbContainerName="$entityId-itcm-db" | |
21 appContainerName="$entityId-itcm-app" | |
22 target="itcmdb" | |
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 |