# HG changeset patch # User Matt Calmes # Date 1635388594 14400 # Node ID b3909bd1a2b6ee7ffd59e923170d842cfc434096 # Parent 326978b4b0be1f6dfee8112bdc5a3437cd2a9a10 INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script diff -r 326978b4b0be -r b3909bd1a2b6 scripts/backup-container-docker.sh --- a/scripts/backup-container-docker.sh Wed Oct 27 15:21:57 2021 -0400 +++ b/scripts/backup-container-docker.sh Wed Oct 27 22:36:34 2021 -0400 @@ -31,7 +31,7 @@ fi ##Take out the extra space from IRN returned from db. IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'` - backupFile=./backup/${IRN}${entityId}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup + backupFile=./backup/${IRN}${entityId}-inventory-db.$(date +%Y-%m-%d-%H-%M-%S).backup echo "entityId is $entityId" echo "container name is $containerName" fi @@ -42,7 +42,7 @@ } entityId=$(prop 'entityId' | tr -d '"') containerName="$entityId-workflows-db" - backupFile=./backup/${entityId}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup + backupFile=./backup/${entityId}-workflows-db.$(date +%Y-%m-%d-%H-%M-%S).backup echo "entityId is $entityId" echo "container name is $containerName" fi @@ -67,5 +67,5 @@ gzip ${backupFile} - echo "completed backup of $container to ${backupFile}" + echo "completed backup of $container to ${backupFile}.gz" fi diff -r 326978b4b0be -r b3909bd1a2b6 scripts/restore-inventory.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/restore-inventory.sh Wed Oct 27 22:36:34 2021 -0400 @@ -0,0 +1,51 @@ +#!/bin/bash + +source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" + +sourceFile=${1?must provide backup file to be restored} + +if [ -z "$1" ] +then + echo "Usage: `basename $0` {backup file to restore}" + echo " must specify the name of the file to restore. Assumed to be in format:" + echo " {IRN}{entityId}-inventory-db.{timestamp}.backup.gz " + exit $E_NOARGS +fi + +function prop { + grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2 +} + +entityId=$(prop 'entityId' | tr -d '"') +dbContainerName="$entityId-inventory-db" +appContainerName="$entityId-inventory-app" +target="invdb" + +echo +echo "Preparing to restore" +echo "--------------------" +echo " file: $sourceFile" +echo " to $dbContainerName database: $target" +echo " " +echo "WARNING: This operation will DELETE and replace any exising database" +echo " " + +read -e -p "Continue? " answer +case $answer in + y | Y | yes | YES ) answer="y";; + n | N | no | NO ) answer="n";; + *) answer="n" +esac + +if [ "$answer" == "y" ] +then + echo "stopping application service $appContainerName" + docker stop $appContainerName + + echo "copy backup file to database container" + docker cp ${sourceFile} ${dbContainerName}:/tmp/restore.backup.gz + + echo "starting database restore" + docker exec -t -u postgres $dbContainerName sh -c "gunzip -f /tmp/restore.backup.gz -c | psql" + +fi