comparison 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
comparison
equal deleted inserted replaced
319:7c460a921709 320:58c49a386a11
18 project=$(composeGetProject) 18 project=$(composeGetProject)
19 19
20 set -o pipefail 20 set -o pipefail
21 mkdir -p ./backup 21 mkdir -p ./backup
22 ## 22 ##
23 ##THis one puts a space before the IRN 23 ##This one puts a space before the IRN
24 IRN=$(docker-compose exec -T $container psql --username=postgres --dbname=$container -t -c 'select irn from organization') 24 IRN=$(docker-compose exec -T $container psql --username=postgres --dbname=$container -t -c 'select irn from organization')
25 ##Trim function in postgres didn't work - so take out the extra space this way. 25 ##Trim function in postgres didn't work - so take out the extra space this way.
26 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'` 26 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'`
27 27
28 ## if database is empty, it will put IRN 000000
29 if [ "$IRN" == "" ]; then
30 echo "no IRN set,using 000000"
31 IRN=000000
32 fi
33
28 backupFile=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup 34 backupFile=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup
29 #echo "IRNS${IRNS}" 35
30 echo "IRN${IRN}" 36 echo "IRN${IRN}"
31 37
32 echo "backup file ${backupFile}" 38 echo "backup file ${backupFile}"
33 echo "preparing to backup ${container} on current project at ${projectDir}:" 39 echo "preparing to backup ${container} on current project at ${projectDir}:"
34 echo " " 40 echo " "
35 41
36 42 #If the project is empty, we want to stop the process because this is being run from the wrong directory
37 43
38 if [ "$project" == "" ]; then 44 if [ "$project" == "" ]; then
39 echo "no project available" 45 echo "no project available"
40 exit 1 46 exit 1
41 fi 47 fi
43 echo "starting backup of $container for $project" 49 echo "starting backup of $container for $project"
44 docker-compose exec -T $container sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile} 50 docker-compose exec -T $container sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile}
45 51
46 if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then 52 if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then
47 echo "ERROR: backup verification FAILED" 53 echo "ERROR: backup verification FAILED"
54 echo "Error: empty database"
48 echo "ERROR: $(tail ${backupFile})" 55 echo "ERROR: $(tail ${backupFile})"
49 exit 1 56 # We want the process to continue even if the db is blank
57 # exit 1
50 fi 58 fi
51 59
52 gzip ${backupFile} 60 gzip ${backupFile}
53 61
54 62