diff scripts/remote-backup.sh @ 326:b35f4af06ed4 production vv2.6.0

flow: Merged <release> 'v2.6.0' to <master> ('production').
author aldrich@ssdt-ohio.org
date Tue, 12 Nov 2019 16:16:00 +0000
parents 4285b8a2762e
children
line wrap: on
line diff
--- a/scripts/remote-backup.sh	Wed May 01 15:33:00 2019 +0100
+++ b/scripts/remote-backup.sh	Tue Nov 12 16:16:00 2019 +0000
@@ -27,27 +27,44 @@
 
 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
+
+
+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
+
 echo "Project is $project"
 echo "Container is $container"
 echo "Remote target is $remoteTarget"
 echo "Username is $userName"
-
-backupFile=./backup/${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup
-backupFile2=./backup/${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz
+echo "IRN is $IRN"
 
 
-if [ "$project" == "" ]; then
-   echo "no project available"
-   exit 1
-fi
+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
+
+
 
 echo "starting backup of $container for $project"
 docker-compose exec -T $container 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})"
-   exit 1
+  # We want the process to continue even if the db is blank
+  # exit 1
 fi
 
 gzip ${backupFile}
@@ -55,17 +72,25 @@
 echo "completed backup of $container for $project to ${backupFile}"
 
 #backup of all files in current directory
-tar -czf ${backupFile2} . --exclude=./backup
+#tar -czf ${backupFile2} . --exclude=./backup
+tar --exclude=./backup -czf ${backupFile2} .
 
 echo "completed backup of all files for $project to ${backupFile2}"
 
+#Create remote directory before scp
 
+host=`echo $userName@$remoteTarget | sed -e 's/:.*//'`
+
+target=`echo $remoteTarget | sed -e 's/.*://'`
+
+ssh $host mkdir -p $target/$project
+
+#scp file 
 #
-#
-scp ${backupFile}.gz  ${backupFile2} $userName@$remoteTarget
+scp ${backupFile}.gz  ${backupFile2} $userName@$remoteTarget/$project
 
 echo " "
 
-echo "completed sending ${backupFile}.gz and ${backupFile2} to ${remoteTarget} as user $userName"
+echo "completed sending ${backupFile}.gz and ${backupFile2} to ${remoteTarget}/${project} as user $userName"