changeset 393:56498d910235

INV-197 refine backup-container-docker.sh script
author Matt Calmes <calmes@ssdt-ohio.org>
date Mon, 25 Oct 2021 13:41:56 -0400
parents 53c399aaa85d
children 326978b4b0be
files scripts/backup-container-docker.sh
diffstat 1 files changed, 20 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/backup-container-docker.sh	Mon Oct 25 13:00:06 2021 -0400
+++ b/scripts/backup-container-docker.sh	Mon Oct 25 13:41:56 2021 -0400
@@ -17,7 +17,7 @@
 set -o pipefail
 mkdir -p ./backup
 
-if [ "$container" = "invdb" ]; then
+if [[ "$container" = "invdb" && -f ".env/ssdt-inventory-shared.properties" ]]; then
    function prop {
        grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2
    }
@@ -36,7 +36,7 @@
    echo "container name is $containerName"
 fi
 
-if [ "$container" = "workflowsdb" ]; then
+if [[ "$container" = "workflowsdb" && -f ".env/ssdt-workflows-shared.properties" ]]; then
    function prop {
        grep "${1}" .env/ssdt-workflows-shared.properties|cut -d'=' -f2
    }
@@ -47,24 +47,25 @@
    echo "container name is $containerName"
 fi
 
-echo "Container is $container"
-echo "IRN is $IRN"
+if [ ! -z "$containerName" ]; then
+   echo "Container is $container"
+   echo "IRN is $IRN"
 
-echo "backup file ${backupFile}"
-echo "preparing to backup ${container} on current project at ${projectDir}:"
-echo " "
+   echo "backup file ${backupFile}"
+   echo "preparing to backup ${container} on current project at ${projectDir}:"
+   echo " "
 
-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"
-#   echo "Error: empty database"
-#   echo "ERROR: $(tail ${backupFile})"
-  # We want the process to continue even if the db is blank
-  # exit 1
-#fi
+   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"
+   #   echo "Error: empty database"
+   #   echo "ERROR: $(tail ${backupFile})"
+   # We want the process to continue even if the db is blank
+   # exit 1
+   #fi
 
-gzip ${backupFile}
+   gzip ${backupFile}
 
-echo "completed backup of $container to ${backupFile}"
-
+   echo "completed backup of $container to ${backupFile}"
+fi