comparison scripts/backup-container.sh @ 188:2f5f41d237e7

DEP-12: fix backup script.
author smith@nwoca.org
date Wed, 20 Sep 2017 17:01:09 +0100
parents 620ea742f1df
children fcee81af7e71
comparison
equal deleted inserted replaced
187:6b950e1a95e6 188:2f5f41d237e7
6 # When successful, the output file will be in ./backup with the 6 # When successful, the output file will be in ./backup with the
7 # container name and timestamp in the file. The format of the output 7 # container name and timestamp in the file. The format of the output
8 # is a compressed pg_dump (sql) format. 8 # is a compressed pg_dump (sql) format.
9 # 9 #
10 container=${1?Must provide container name to backup} 10 container=${1?Must provide container name to backup}
11
12 projectDir=${2:-$PWD}
13
14 cd $projectDir
11 15
12 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" 16 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
13 17
14 set -o pipefail 18 set -o pipefail
15 mkdir -p ./backup 19 mkdir -p ./backup
21 echo "no project available" 25 echo "no project available"
22 exit 1 26 exit 1
23 fi 27 fi
24 28
25 echo "starting backup of $container for $project" 29 echo "starting backup of $container for $project"
26 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}
27 31
28 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
29 echo "ERROR: backup verification FAILED" 33 echo "ERROR: backup verification FAILED"
30 echo "ERROR: $(tail ${backupFile})" 34 echo "ERROR: $(tail ${backupFile})"
31 exit 1 35 exit 1