changeset 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 7c460a921709
children 2cb1093f9aef
files scripts/backup-container.sh scripts/remote-backup-all.sh scripts/remote-backup.sh
diffstat 3 files changed, 35 insertions(+), 8 deletions(-) [+]
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}
--- a/scripts/remote-backup-all.sh	Thu Oct 31 11:40:53 2019 +0100
+++ b/scripts/remote-backup-all.sh	Thu Oct 31 14:34:53 2019 +0100
@@ -29,11 +29,14 @@
 
 project=$(composeGetProject)
 
+#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
 
+## first will try to get IRNfrom usasdb; if that is empty it will try to get it from uspsdb
 
 IRN=$(docker-compose exec -T $container1 psql --username=postgres --dbname=$container1 -t -c 'select irn from organization') 
 
@@ -44,6 +47,12 @@
 ##Trim function in postgres didn't work - so take out the extra space this way.
 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'`
 
+## if both database are empty, it will put IRN 000000
+if [ "$IRN" == "" ]; then
+   echo "no IRN set, using 000000"
+    IRN=000000
+fi
+
 echo "project is $project"
 echo "Containers are $container1 and $container2"
 echo "Remote target is $remoteTarget"
@@ -62,7 +71,8 @@
   if [[ $( grep --count "CREATE TABLE" ${backupFile1} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile1} ) -eq 0 ]]; then
      echo "ERROR: backup verification FAILED"
      echo "ERROR:  $(tail ${backupFile1})"
-     else
+	 echo "Error: empty database"
+	 #else  We still gzip the backup file
      gzip ${backupFile1}
 
      echo "completed backup of $container1 for $project to ${backupFile1}"
@@ -79,7 +89,8 @@
   if [[ $( grep --count "CREATE TABLE" ${backupFile2} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile2} ) -eq 0 ]]; then
      echo "ERROR: backup verification FAILED"
      echo "ERROR:  $(tail ${backupFile2})"
-     else
+	 echo "Error: empty database"
+     #else  We still gzip the backup file
      gzip ${backupFile2}
 
      echo "completed backup of $container2 for $project to ${backupFile2}"
--- a/scripts/remote-backup.sh	Thu Oct 31 11:40:53 2019 +0100
+++ b/scripts/remote-backup.sh	Thu Oct 31 14:34:53 2019 +0100
@@ -31,6 +31,12 @@
 ##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
+
 echo "Project is $project"
 echo "Container is $container"
 echo "Remote target is $remoteTarget"
@@ -40,7 +46,7 @@
 backupFile=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup
 backupFile2=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz
 
-
+#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
@@ -51,8 +57,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}