comparison scripts/backup-container.sh @ 267:fcee81af7e71

simplify method of getting project name
author smith@nwoca.org
date Mon, 12 Nov 2018 21:21:00 +0000
parents 2f5f41d237e7
children 7723b18b112b
comparison
equal deleted inserted replaced
266:b72855a930f1 267:fcee81af7e71
17 17
18 set -o pipefail 18 set -o pipefail
19 mkdir -p ./backup 19 mkdir -p ./backup
20 backupFile=./backup/${container}.$(date +%Y-%m-%d-%H-%M-%S).backup 20 backupFile=./backup/${container}.$(date +%Y-%m-%d-%H-%M-%S).backup
21 21
22 project=$(composeGetProject $container) 22 project=$(composeGetProject)
23 23
24 if [ "$project" == "" ]; then 24 if [ "$project" == "" ]; then
25 echo "no project available" 25 echo "no project available"
26 exit 1 26 exit 1
27 fi 27 fi
29 echo "starting backup of $container for $project" 29 echo "starting backup of $container for $project"
30 docker-compose exec -T $container sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile} 30 docker-compose exec -T $container sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile}
31 31
32 if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then 32 if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then
33 echo "ERROR: backup verification FAILED" 33 echo "ERROR: backup verification FAILED"
34 echo "ERROR: $(tail ${backupFile})" 34 echo "ERROR: $(tail ${backupFile})"
35 exit 1 35 exit 1
36 fi 36 fi
37 37
38 gzip ${backupFile} 38 gzip ${backupFile}
39 39