changeset 389:4e42c10e3c0d

INV-197 update db backup helper scripts for inventory and workflow
author Matt Calmes <calmes@ssdt-ohio.org>
date Mon, 18 Oct 2021 07:05:16 -0400
parents 23d40b345e1e
children d75786228e6b
files scripts/backup-container-docker.sh scripts/backup-inventory.sh
diffstat 2 files changed, 5 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/backup-container-docker.sh	Mon Oct 18 06:33:33 2021 -0400
+++ b/scripts/backup-container-docker.sh	Mon Oct 18 07:05:16 2021 -0400
@@ -8,11 +8,8 @@
 # is a compressed pg_dump (sql) format.
 #
 container=${1?Must provide container name to backup}
-
 projectDir=${2:-$PWD}
 
-project=${3?Must provide project name to backup}
-
 cd $projectDir
 
 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
@@ -27,30 +24,19 @@
    entityId=$(prop 'entityId' | tr -d '"')
    containerName="$entityId-inventory-db"
    IRN=$(docker exec $containerName psql --username=postgres --dbname=$container -t -c 'select districtirn from inventoryconfiguration')
+   ##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
    echo "entityId is $entityId"
    echo "container name is $containerName"
 fi
 
-#If the project is empty, we want to stop the process because this is being run from the wrong directory
-
-#if [ "$project" == "" ]; then
-#   echo "no project available"
-#   exit 1
-#fi
-#
-##Take out the extra space from IRN returned from db.
-IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'`
-
 ## if database is empty, it will put IRN 000000
 if [ "$IRN" == "" ]; then
    echo "no IRN set,using 000000"
     IRN=000000
 fi
 
-
-
-echo "Project is $project"
 echo "Container is $container"
 echo "IRN is $IRN"
 
@@ -58,9 +44,7 @@
 echo "preparing to backup ${container} on current project at ${projectDir}:"
 echo " "
 
-
-
-echo "starting backup of $container for $project"
+echo "starting backup of $container"
 docker exec -t $containerName sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile}
 #if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then
 #   echo "ERROR: backup verification FAILED"
@@ -72,6 +56,5 @@
 
 gzip ${backupFile}
 
+echo "completed backup of $container to ${backupFile}"
 
-echo "completed backup of $container for $project to ${backupFile}"
-
--- a/scripts/backup-inventory.sh	Mon Oct 18 06:33:33 2021 -0400
+++ b/scripts/backup-inventory.sh	Mon Oct 18 07:05:16 2021 -0400
@@ -2,5 +2,5 @@
 
 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
 
-${SSDT_SCRIPTS}/backup-container-docker.sh invdb ${1} inventory
+${SSDT_SCRIPTS}/backup-container-docker.sh invdb ${1}