comparison scripts/remote-backup.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 7c460a921709
children 2cb1093f9aef
comparison
equal deleted inserted replaced
319:7c460a921709 320:58c49a386a11
29 29
30 IRN=$(docker-compose exec -T $container psql --username=postgres --dbname=$container -t -c 'select irn from organization') 30 IRN=$(docker-compose exec -T $container psql --username=postgres --dbname=$container -t -c 'select irn from organization')
31 ##Trim function in postgres didn't work - so take out the extra space this way. 31 ##Trim function in postgres didn't work - so take out the extra space this way.
32 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'` 32 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'`
33 33
34 ## if database is empty, it will put IRN 000000
35 if [ "$IRN" == "" ]; then
36 echo "no IRN set, using 000000"
37 IRN=000000
38 fi
39
34 echo "Project is $project" 40 echo "Project is $project"
35 echo "Container is $container" 41 echo "Container is $container"
36 echo "Remote target is $remoteTarget" 42 echo "Remote target is $remoteTarget"
37 echo "Username is $userName" 43 echo "Username is $userName"
38 echo "IRN is $IRN" 44 echo "IRN is $IRN"
39 45
40 backupFile=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup 46 backupFile=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup
41 backupFile2=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz 47 backupFile2=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz
42 48
43 49 #If the project is empty, we want to stop the process because this is being run from the wrong directory
44 if [ "$project" == "" ]; then 50 if [ "$project" == "" ]; then
45 echo "no project available" 51 echo "no project available"
46 exit 1 52 exit 1
47 fi 53 fi
48 54
49 echo "starting backup of $container for $project" 55 echo "starting backup of $container for $project"
50 docker-compose exec -T $container sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile} 56 docker-compose exec -T $container sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile}
51 57
52 if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then 58 if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then
53 echo "ERROR: backup verification FAILED" 59 echo "ERROR: backup verification FAILED"
60 echo "Error: empty database"
54 echo "ERROR: $(tail ${backupFile})" 61 echo "ERROR: $(tail ${backupFile})"
55 exit 1 62 # We want the process to continue even if the db is blank
63 # exit 1
56 fi 64 fi
57 65
58 gzip ${backupFile} 66 gzip ${backupFile}
59 67
60 echo "completed backup of $container for $project to ${backupFile}" 68 echo "completed backup of $container for $project to ${backupFile}"