Mercurial > public > ssdt-docker
changeset 399:bfed402ab6b0 production
INV-197 merge release/v2.13.0 into production
author | Matt Calmes <calmes@ssdt-ohio.org> |
---|---|
date | Thu, 28 Oct 2021 07:55:48 -0400 |
parents | d6f2270566e9 (current diff) 3f76ce6790fb (diff) |
children | 3508fd2d323a |
files | prod/install-workflows-app.sh prod/install-workflows-db.sh prod/update-workflows-app.sh |
diffstat | 6 files changed, 227 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/backup-container-docker.sh Thu Oct 28 07:55:48 2021 -0400 @@ -0,0 +1,72 @@ +#!/bin/bash +# Executes a database backup for the specifed database container. +# The current directory is expected to contain a project configured +# as with SSDT conventions for an application database. +# +# When successful, the output file will be in ./backup with the +# container name and timestamp in the file. The format of the output +# is a compressed pg_dump (sql) format. +# +container=${1?Must provide container name to backup} +projectDir=${2:-$PWD} + +cd $projectDir + +source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" + +set -o pipefail +mkdir -p ./backup + +if [[ "$container" = "invdb" && -f ".env/ssdt-inventory-shared.properties" ]]; then + function prop { + grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2 + } + entityId=$(prop 'entityId' | tr -d '"') + containerName="$entityId-inventory-db" + IRN=$(docker exec $containerName psql --username=postgres --dbname=$container -t -c 'select districtirn from inventoryconfiguration') + ## if database is empty, it will put IRN 000000 + if [ "$IRN" == "" ]; then + echo "no IRN set,using 000000" + IRN=000000 + fi + ##Take out the extra space from IRN returned from db. + IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'` + backupFile=./backup/${IRN}${entityId}-inventory-db.$(date +%Y-%m-%d-%H-%M-%S).backup + echo "entityId is $entityId" + echo "container name is $containerName" +fi + +if [[ "$container" = "workflowsdb" && -f ".env/ssdt-workflows-shared.properties" ]]; then + function prop { + grep "${1}" .env/ssdt-workflows-shared.properties|cut -d'=' -f2 + } + entityId=$(prop 'entityId' | tr -d '"') + containerName="$entityId-workflows-db" + backupFile=./backup/${entityId}-workflows-db.$(date +%Y-%m-%d-%H-%M-%S).backup + echo "entityId is $entityId" + echo "container name is $containerName" +fi + +if [ ! -z "$containerName" ]; then + echo "Container is $container" + if [ "$container" = "invdb" ]; then + echo "IRN is $IRN" + fi + echo "backup file ${backupFile}" + echo "preparing to backup ${container} on current project at ${projectDir}:" + echo " " + + echo "starting backup of $container" + docker exec -t $containerName sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile} + #if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then + # echo "ERROR: backup verification FAILED" + # echo "Error: empty database" + # echo "ERROR: $(tail ${backupFile})" + # We want the process to continue even if the db is blank + # exit 1 + #fi + + gzip ${backupFile} + + echo "completed backup of $container to ${backupFile}.gz" +fi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/backup-inventory.sh Thu Oct 28 07:55:48 2021 -0400 @@ -0,0 +1,6 @@ +#!/bin/bash + +source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" + +${SSDT_SCRIPTS}/backup-container-docker.sh invdb ${1} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/backup-workflow.sh Thu Oct 28 07:55:48 2021 -0400 @@ -0,0 +1,5 @@ +#!/bin/bash + +source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" + +${SSDT_SCRIPTS}/backup-container-docker.sh workflowsdb ${1}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/exec-all-projects-docker.sh Thu Oct 28 07:55:48 2021 -0400 @@ -0,0 +1,42 @@ +#!/bin/bash +# Scans for standard SSDT docker projects in specified parent path and +# executes the specified command. +# +# The first parameter specifices the parent directory to search for. +# +# The second parameter specifies the command to execute against each +# SSDT standard docker project found under the parent directory. +# +# examples: +# +# /ssdt/scripts/exec-all-projects-docker.sh /data/prod /ssdt/scripts/backup-inventory.sh +# +# runs backup-inventory.sh script against all projects under /data/prod +# +## + +source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" + +: ${1?"Usage: {parent path} [command]"} + +ORIGINALDIR=$PWD +PARENTDIR=$1 + +shift +COMMAND=$@ + +for f in $(find $PARENTDIR -type d -name .env) +do + projectdir=`dirname $f` + project=`basename $projectdir` + cd $projectdir + if ls .env/ssdt-*-shared.properties 1> /dev/null 2>&1; then + echo "projectdir is $projectdir" + echo -e "----\n$executing $COMMAND on $project \n----" + + bash -c "${COMMAND}" + echo "" + fi +done + +cd $ORIGINALDIR
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/restore-inventory.sh Thu Oct 28 07:55:48 2021 -0400 @@ -0,0 +1,51 @@ +#!/bin/bash + +source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" + +sourceFile=${1?must provide backup file to be restored} + +if [ -z "$1" ] +then + echo "Usage: `basename $0` {backup file to restore}" + echo " must specify the name of the file to restore. Assumed to be in format:" + echo " {IRN}{entityId}-inventory-db.{timestamp}.backup.gz " + exit $E_NOARGS +fi + +function prop { + grep "${1}" .env/ssdt-inventory-shared.properties|cut -d'=' -f2 +} + +entityId=$(prop 'entityId' | tr -d '"') +dbContainerName="$entityId-inventory-db" +appContainerName="$entityId-inventory-app" +target="invdb" + +echo +echo "Preparing to restore" +echo "--------------------" +echo " file: $sourceFile" +echo " to $dbContainerName database: $target" +echo " " +echo "WARNING: This operation will DELETE and replace any exising database" +echo " " + +read -e -p "Continue? <y/N> " answer +case $answer in + y | Y | yes | YES ) answer="y";; + n | N | no | NO ) answer="n";; + *) answer="n" +esac + +if [ "$answer" == "y" ] +then + echo "stopping application service $appContainerName" + docker stop $appContainerName + + echo "copy backup file to database container" + docker cp ${sourceFile} ${dbContainerName}:/tmp/restore.backup.gz + + echo "starting database restore" + docker exec -t -u postgres $dbContainerName sh -c "gunzip -f /tmp/restore.backup.gz -c | psql" + +fi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/restore-workflow.sh Thu Oct 28 07:55:48 2021 -0400 @@ -0,0 +1,51 @@ +#!/bin/bash + +source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" + +sourceFile=${1?must provide backup file to be restored} + +if [ -z "$1" ] +then + echo "Usage: `basename $0` {backup file to restore}" + echo " must specify the name of the file to restore. Assumed to be in format:" + echo " {entityId}-workflows-db.{timestamp}.backup.gz " + exit $E_NOARGS +fi + +function prop { + grep "${1}" .env/ssdt-workflows-shared.properties|cut -d'=' -f2 +} + +entityId=$(prop 'entityId' | tr -d '"') +dbContainerName="$entityId-workflows-db" +appContainerName="$entityId-workflows-app" +target="workflowsdb" + +echo +echo "Preparing to restore" +echo "--------------------" +echo " file: $sourceFile" +echo " to $dbContainerName database: $target" +echo " " +echo "WARNING: This operation will DELETE and replace any exising database" +echo " " + +read -e -p "Continue? <y/N> " answer +case $answer in + y | Y | yes | YES ) answer="y";; + n | N | no | NO ) answer="n";; + *) answer="n" +esac + +if [ "$answer" == "y" ] +then + echo "stopping application service $appContainerName" + docker stop $appContainerName + + echo "copy backup file to database container" + docker cp ${sourceFile} ${dbContainerName}:/tmp/restore.backup.gz + + echo "starting database restore" + docker exec -t -u postgres $dbContainerName sh -c "gunzip -f /tmp/restore.backup.gz -c | psql" + +fi