diff scripts/backup-container.sh @ 320:58c49a386a11

making changes to remote backup scripts to create directory
author aldrich@ssdt-ohio.org
date Thu, 31 Oct 2019 14:34:53 +0100
parents d78b45c28205
children 2cb1093f9aef
line wrap: on
line diff
--- a/scripts/backup-container.sh	Thu Oct 31 11:40:53 2019 +0100
+++ b/scripts/backup-container.sh	Thu Oct 31 14:34:53 2019 +0100
@@ -20,20 +20,26 @@
 set -o pipefail
 mkdir -p ./backup
 ##
-##THis one puts a space before the IRN
+##This one puts a space before the IRN
 IRN=$(docker-compose exec -T $container psql --username=postgres --dbname=$container -t -c 'select irn from organization') 
 ##Trim function in postgres didn't work - so take out the extra space this way.
 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
+
 backupFile=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup
-#echo "IRNS${IRNS}"
+
 echo "IRN${IRN}"
 
 echo "backup file ${backupFile}"
 echo "preparing to backup ${container} on current project at ${projectDir}:"
 echo " "
 
-
+#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"
@@ -45,8 +51,10 @@
 
 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})"
-   exit 1
+  # We want the process to continue even if the db is blank
+  # exit 1
 fi
 
 gzip ${backupFile}