changeset 314:d78b45c28205

backup script adding IRN to name
author aldrich@ssdt-ohio.org
date Mon, 28 Oct 2019 19:43:53 +0100
parents 06e92ad77e7f
children b67ceb4b6d04
files scripts/backup-container.sh scripts/remote-backup-all.sh scripts/remote-backup.sh
diffstat 3 files changed, 40 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/backup-container.sh	Thu Jun 27 19:21:53 2019 +0100
+++ b/scripts/backup-container.sh	Mon Oct 28 19:43:53 2019 +0100
@@ -19,8 +19,17 @@
 
 set -o pipefail
 mkdir -p ./backup
-backupFile=./backup/${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup
+##
+##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:]]*//'`
 
+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 " "
 
--- a/scripts/remote-backup-all.sh	Thu Jun 27 19:21:53 2019 +0100
+++ b/scripts/remote-backup-all.sh	Mon Oct 28 19:43:53 2019 +0100
@@ -12,7 +12,6 @@
 # This will backup both usasdb and uspsdb,
 # along with the top level contents of the project directory
 #Environment variables can be used for REMOTE_BACKUP_TARGET and REMOTE_USERNAME
-
 remoteTarget=${1:-$REMOTE_BACKUP_TARGET}
 userName=${2:-$REMOTE_USERNAME}
 projectDir=${3:-$PWD}
@@ -30,20 +29,31 @@
 
 project=$(composeGetProject)
 
-echo "project is $project"
-echo "Containers are $container1 and $container2"
-echo "Remote target is $remoteTarget"
-echo "Username is $userName"
-
 if [ "$project" == "" ]; then
    echo "no project available"
    exit 1
 fi
 
 
-backupFile1=./backup/${project}-${container1}.$(date +%Y-%m-%d-%H-%M-%S).backup
-backupFile2=./backup/${project}-${container2}.$(date +%Y-%m-%d-%H-%M-%S).backup
-backupFile3=./backup/${project}-directory.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz
+IRN=$(docker-compose exec -T $container1 psql --username=postgres --dbname=$container1 -t -c 'select irn from organization') 
+
+if ["$IRN" == ""]; then
+IRN=$(docker-compose exec -T $container2 psql --username=postgres --dbname=$container2 -t -c 'select irn from organization') 
+fi
+
+##Trim function in postgres didn't work - so take out the extra space this way.
+IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'`
+
+echo "project is $project"
+echo "Containers are $container1 and $container2"
+echo "Remote target is $remoteTarget"
+echo "Username is $userName"
+echo "IRN is $IRN"
+
+
+backupFile1=./backup/${IRN}${project}-${container1}.$(date +%Y-%m-%d-%H-%M-%S).backup
+backupFile2=./backup/${IRN}${project}-${container2}.$(date +%Y-%m-%d-%H-%M-%S).backup
+backupFile3=./backup/${IRN}${project}-directory.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz
 
 #usasdb
 echo "starting backup of $container1 for $project"
@@ -81,7 +91,8 @@
 #backup of all files in current directory
 echo "starting backup of current directory for $project"
 
-tar -czf ${backupFile3} . --exclude=./backup
+#tar -czf ${backupFile3} . --exclude=./backup
+tar --exclude=./backup -czf ${backupFile3} . --exclude=./backup
 
 echo "completed backup of all files for $project to ${backupFile3}"
 
--- a/scripts/remote-backup.sh	Thu Jun 27 19:21:53 2019 +0100
+++ b/scripts/remote-backup.sh	Mon Oct 28 19:43:53 2019 +0100
@@ -27,13 +27,18 @@
 
 project=$(composeGetProject)
 
+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:]]*//'`
+
 echo "Project is $project"
 echo "Container is $container"
 echo "Remote target is $remoteTarget"
 echo "Username is $userName"
+echo "IRN is $IRN"
 
-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
+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 [ "$project" == "" ]; then
@@ -55,7 +60,8 @@
 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}"