comparison scripts/restore-inventory.sh @ 395:b3909bd1a2b6

INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
author Matt Calmes <calmes@ssdt-ohio.org>
date Wed, 27 Oct 2021 22:36:34 -0400
parents
children
comparison
equal deleted inserted replaced
394:326978b4b0be 395:b3909bd1a2b6
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 " {IRN}{entityId}-inventory-db.{timestamp}.backup.gz "
12 exit $E_NOARGS
13 fi
14
15 function prop {
16 grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2
17 }
18
19 entityId=$(prop 'entityId' | tr -d '"')
20 dbContainerName="$entityId-inventory-db"
21 appContainerName="$entityId-inventory-app"
22 target="invdb"
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