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