From 6256ecd1b707d935577a2b830cdaa3c7c67af847 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Sun, 20 Aug 2023 20:46:21 -0400 Subject: [PATCH] Refactor Backup --- www/backup_www.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ www/go.sh | 30 ------------------------------ 2 files changed, 47 insertions(+), 30 deletions(-) create mode 100755 www/backup_www.sh diff --git a/www/backup_www.sh b/www/backup_www.sh new file mode 100755 index 0000000..12a99d3 --- /dev/null +++ b/www/backup_www.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -exu +cd "$(dirname "$0")" + +APP= + +# grab any modifications from the command line. +for i in "$@"; do + case $i in + --app=*) + APP="${i#*=}" + shift + ;; + + *) + echo "Unexpected option: $1" + exit 1 + ;; + esac +done + +if [ -z "$APP" ]; then + echo "ERROR: You must specify the --app= paramater." + exit 1 +fi + +for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do + export DOMAIN_NAME="$DOMAIN_NAME" + export SITE_PATH="$SITES_PATH/$DOMAIN_NAME" + + # source the site path so we know what features it has. + source ../../deployment_defaults.sh + source ../project_defaults.sh + source "$SITE_PATH/site.conf" + source ../domain_env.sh + + # these variable are used by both backup/restore scripts. + export REMOTE_BACKUP_PATH="$REMOTE_BACKUP_PATH/www/$APP/$DOMAIN_IDENTIFIER" + export REMOTE_SOURCE_BACKUP_PATH="$REMOTE_DATA_PATH/$APP/$DOMAIN_NAME" + + # ensure our local backup path exists so we can pull down the duplicity archive to the management machine. + export LOCAL_BACKUP_PATH="$SITE_PATH/backups/www/$APP" + mkdir -p "$LOCAL_BACKUP_PATH" + + ./backup_path.sh +done diff --git a/www/go.sh b/www/go.sh index 2dd37fc..9f428f9 100755 --- a/www/go.sh +++ b/www/go.sh @@ -87,36 +87,6 @@ if [ "$RUN_CERT_RENEWAL" = true ] && [ "$RESTORE_CERTS" = false ] && [ "$STACKS_ ./generate_certs.sh fi -# let's backup all our letsencrypt certs -export APP="letsencrypt" -for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do - export DOMAIN_NAME="$DOMAIN_NAME" - export SITE_PATH="$SITES_PATH/$DOMAIN_NAME" - - # source the site path so we know what features it has. - source ../../deployment_defaults.sh - source ../project_defaults.sh - source "$SITE_PATH/site.conf" - source ../domain_env.sh - - # these variable are used by both backup/restore scripts. - export REMOTE_BACKUP_PATH="$REMOTE_BACKUP_PATH/www/$APP/$DOMAIN_IDENTIFIER" - export REMOTE_SOURCE_BACKUP_PATH="$REMOTE_DATA_PATH/$APP/$DOMAIN_NAME" - - # ensure our local backup path exists so we can pull down the duplicity archive to the management machine. - export LOCAL_BACKUP_PATH="$SITE_PATH/backups/www/$APP" - mkdir -p "$LOCAL_BACKUP_PATH" - - # we grab a backup of the certs unless we're restoring. - if [ "$RESTORE_CERTS" = true ]; then - ./restore_path.sh - else - if [ "$BACKUP_WWW_APPS" = true ]; then - ./backup_path.sh - fi - fi -done - # nginx gets deployed first since it "owns" the docker networks of downstream services. ./stub/nginx_yml.sh