Mercurial > public > ssdt-docker
comparison scripts/backup-container-docker.sh @ 393:56498d910235
INV-197 refine backup-container-docker.sh script
author | Matt Calmes <calmes@ssdt-ohio.org> |
---|---|
date | Mon, 25 Oct 2021 13:41:56 -0400 |
parents | d75786228e6b |
children | b3909bd1a2b6 |
comparison
equal
deleted
inserted
replaced
392:53c399aaa85d | 393:56498d910235 |
---|---|
15 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" | 15 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" |
16 | 16 |
17 set -o pipefail | 17 set -o pipefail |
18 mkdir -p ./backup | 18 mkdir -p ./backup |
19 | 19 |
20 if [ "$container" = "invdb" ]; then | 20 if [[ "$container" = "invdb" && -f ".env/ssdt-inventory-shared.properties" ]]; then |
21 function prop { | 21 function prop { |
22 grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2 | 22 grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2 |
23 } | 23 } |
24 entityId=$(prop 'entityId' | tr -d '"') | 24 entityId=$(prop 'entityId' | tr -d '"') |
25 containerName="$entityId-inventory-db" | 25 containerName="$entityId-inventory-db" |
34 backupFile=./backup/${IRN}${entityId}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup | 34 backupFile=./backup/${IRN}${entityId}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup |
35 echo "entityId is $entityId" | 35 echo "entityId is $entityId" |
36 echo "container name is $containerName" | 36 echo "container name is $containerName" |
37 fi | 37 fi |
38 | 38 |
39 if [ "$container" = "workflowsdb" ]; then | 39 if [[ "$container" = "workflowsdb" && -f ".env/ssdt-workflows-shared.properties" ]]; then |
40 function prop { | 40 function prop { |
41 grep "${1}" .env/ssdt-workflows-shared.properties|cut -d'=' -f2 | 41 grep "${1}" .env/ssdt-workflows-shared.properties|cut -d'=' -f2 |
42 } | 42 } |
43 entityId=$(prop 'entityId' | tr -d '"') | 43 entityId=$(prop 'entityId' | tr -d '"') |
44 containerName="$entityId-workflows-db" | 44 containerName="$entityId-workflows-db" |
45 backupFile=./backup/${entityId}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup | 45 backupFile=./backup/${entityId}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup |
46 echo "entityId is $entityId" | 46 echo "entityId is $entityId" |
47 echo "container name is $containerName" | 47 echo "container name is $containerName" |
48 fi | 48 fi |
49 | 49 |
50 echo "Container is $container" | 50 if [ ! -z "$containerName" ]; then |
51 echo "IRN is $IRN" | 51 echo "Container is $container" |
52 echo "IRN is $IRN" | |
52 | 53 |
53 echo "backup file ${backupFile}" | 54 echo "backup file ${backupFile}" |
54 echo "preparing to backup ${container} on current project at ${projectDir}:" | 55 echo "preparing to backup ${container} on current project at ${projectDir}:" |
55 echo " " | 56 echo " " |
56 | 57 |
57 echo "starting backup of $container" | 58 echo "starting backup of $container" |
58 docker exec -t $containerName sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile} | 59 docker exec -t $containerName sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile} |
59 #if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then | 60 #if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then |
60 # echo "ERROR: backup verification FAILED" | 61 # echo "ERROR: backup verification FAILED" |
61 # echo "Error: empty database" | 62 # echo "Error: empty database" |
62 # echo "ERROR: $(tail ${backupFile})" | 63 # echo "ERROR: $(tail ${backupFile})" |
63 # We want the process to continue even if the db is blank | 64 # We want the process to continue even if the db is blank |
64 # exit 1 | 65 # exit 1 |
65 #fi | 66 #fi |
66 | 67 |
67 gzip ${backupFile} | 68 gzip ${backupFile} |
68 | 69 |
69 echo "completed backup of $container to ${backupFile}" | 70 echo "completed backup of $container to ${backupFile}" |
70 | 71 fi |