annotate scripts/backup-container-docker.sh @ 419:a524a67503dc release/2.16.0

flow: Closed <release> '2.16.0'.
author Jason Klinger <klinger@nwoca.org>
date Tue, 09 May 2023 18:34:52 +0100
parents 886a7dc796b8
children 8ddeb5a36678
rev   line source
388
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
1 #!/bin/bash
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
2 # Executes a database backup for the specifed database container.
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
3 # The current directory is expected to contain a project configured
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
4 # as with SSDT conventions for an application database.
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
5 #
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
6 # When successful, the output file will be in ./backup with the
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
7 # container name and timestamp in the file. The format of the output
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
8 # is a compressed pg_dump (sql) format.
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
9 #
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
10 container=${1?Must provide container name to backup}
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
11 projectDir=${2:-$PWD}
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
12
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
13 cd $projectDir
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
14
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
15 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
16
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
17 set -o pipefail
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
18 mkdir -p ./backup
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
19
393
56498d910235 INV-197 refine backup-container-docker.sh script
Matt Calmes <calmes@ssdt-ohio.org>
parents: 390
diff changeset
20 if [[ "$container" = "invdb" && -f ".env/ssdt-inventory-shared.properties" ]]; then
388
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
21 function prop {
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
22 grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
23 }
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
24 entityId=$(prop 'entityId' | tr -d '"')
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
25 containerName="$entityId-inventory-db"
23d40b345e1e INV-197 create db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents:
diff changeset
26 IRN=$(docker exec $containerName psql --username=postgres --dbname=$container -t -c 'select districtirn from inventoryconfiguration')
390
d75786228e6b INV-197 wire workflows backup into shared scripts
Matt Calmes <calmes@ssdt-ohio.org>
parents: 389
diff changeset
27 ## if database is empty, it will put IRN 000000
d75786228e6b INV-197 wire workflows backup into shared scripts
Matt Calmes <calmes@ssdt-ohio.org>
parents: 389
diff changeset
28 if [ "$IRN" == "" ]; then
d75786228e6b INV-197 wire workflows backup into shared scripts
Matt Calmes <calmes@ssdt-ohio.org>
parents: 389
diff changeset
29 echo "no IRN set,using 000000"
d75786228e6b INV-197 wire workflows backup into shared scripts
Matt Calmes <calmes@ssdt-ohio.org>
parents: 389
diff changeset
30 IRN=000000
d75786228e6b INV-197 wire workflows backup into shared scripts
Matt Calmes <calmes@ssdt-ohio.org>
parents: 389
diff changeset
31 fi
389
4e42c10e3c0d INV-197 update db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents: 388
diff changeset
32 ##Take out the extra space from IRN returned from db.
4e42c10e3c0d INV-197 update db backup helper scripts for inventory and workflow
Matt Calmes <calmes@ssdt-ohio.org>
parents: 388
diff changeset
33 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'`
395
b3909bd1a2b6 INV-198 fix output of backup-container-docker.sh and create restore-inventory.sh script
Matt Calmes <calmes@ssdt-ohio.org>