Move backup_path.sh up a level, refactors.

This commit is contained in:
Derek Smith 2023-08-11 09:55:57 -04:00
parent 3e5dcb561c
commit a4ebfb19b6
Signed by: farscapian
GPG Key ID: B443E530A14E1C90
2 changed files with 30 additions and 69 deletions

View File

@ -3,11 +3,6 @@
set -exu set -exu
cd "$(dirname "$0")" cd "$(dirname "$0")"
# redirect all docker commands to the remote host.
DOCKER_HOST="ssh://ubuntu@$WWW_FQDN"
export DOCKER_HOST="$DOCKER_HOST"
# Create the nginx config file which covers all domainys. # Create the nginx config file which covers all domainys.
bash -c ./stub/nginx_config.sh bash -c ./stub/nginx_config.sh
@ -77,53 +72,49 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
done done
./stop_docker_stacks.sh
# TODO check if there are any other stacks that are left running (other than reverse proxy) # TODO check if there are any other stacks that are left running (other than reverse proxy)
# if so, this may mean the user has disabled one or more domains and that existing sites/services # if so, this may mean the user has disabled one or more domains and that existing sites/services
# are still running. We should prompt the user of this and quit. They have to go manually docker stack remove these. # are still running. We should prompt the user of this and quit. They have to go manually docker stack remove these.
STACKS_STILL_RUNNING=false
if [[ $(docker stack list | wc -l) -gt 2 ]]; then if [[ $(docker stack list | wc -l) -gt 2 ]]; then
echo "WARNING! You still have stacks running. If you have modified the SITES list, you may need to go remove the docker stacks runnong the remote machine." echo "WARNING! You still have stacks running. If you have modified the SITES list,"
echo "exiting." echo " you may need to go remove the docker stacks running the remote machine."
exit 1 STACKS_STILL_RUNNING=true
fi fi
# ok, the backend stacks are stopped. # generate the certs and grab a backup
if [ "$RESTART_FRONT_END" = true ]; then if [ "$RUN_CERT_RENEWAL" = true ] && [ "$RESTORE_CERTS" = false ] && [ "$STACKS_STILL_RUNNING" = false ]; then
./generate_certs.sh
fi
# generate the certs and grab a backup # let's backup all our letsencrypt certs
if [ "$RUN_CERT_RENEWAL" = true ] && [ "$RESTORE_CERTS" = false ]; then export APP="letsencrypt"
if [ "$STOP_SERVICES" = false ]; then for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
./generate_certs.sh export DOMAIN_NAME="$DOMAIN_NAME"
fi export SITE_PATH="$SITES_PATH/$DOMAIN_NAME"
fi
# let's backup all our letsencrypt certs # source the site path so we know what features it has.
export APP="letsencrypt" source ../../deployment_defaults.sh
for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do source ../project_defaults.sh
export DOMAIN_NAME="$DOMAIN_NAME" source "$SITE_PATH/site.conf"
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME" source ../domain_env.sh
# source the site path so we know what features it has. # these variable are used by both backup/restore scripts.
source ../../deployment_defaults.sh export REMOTE_BACKUP_PATH="$REMOTE_BACKUP_PATH/www/$APP/$DOMAIN_IDENTIFIER"
source ../project_defaults.sh export REMOTE_SOURCE_BACKUP_PATH="$REMOTE_DATA_PATH/$APP/$DOMAIN_NAME"
source "$SITE_PATH/site.conf"
source ../domain_env.sh
# these variable are used by both backup/restore scripts. # ensure our local backup path exists so we can pull down the duplicity archive to the management machine.
export REMOTE_BACKUP_PATH="$REMOTE_BACKUP_PATH/www/$APP/$DOMAIN_IDENTIFIER" export LOCAL_BACKUP_PATH="$SITE_PATH/backups/www/$APP"
export REMOTE_SOURCE_BACKUP_PATH="$REMOTE_DATA_PATH/$APP/$DOMAIN_NAME" mkdir -p "$LOCAL_BACKUP_PATH"
# ensure our local backup path exists so we can pull down the duplicity archive to the management machine. # we grab a backup of the certs unless we're restoring.
export LOCAL_BACKUP_PATH="$SITE_PATH/backups/www/$APP" if [ "$RESTORE_CERTS" = true ]; then
mkdir -p "$LOCAL_BACKUP_PATH" ./restore_path.sh
else
# we grab a backup of the certs unless we're restoring. if [ "$BACKUP_WWW_APPS" = true ]; then
if [ "$RESTORE_CERTS" = true ]; then
./restore_path.sh
else
./backup_path.sh ./backup_path.sh
fi fi
fi
done done
# nginx gets deployed first since it "owns" the docker networks of downstream services. # nginx gets deployed first since it "owns" the docker networks of downstream services.
@ -134,24 +125,3 @@ done
./stub/nextcloud_yml.sh ./stub/nextcloud_yml.sh
./stub/gitea_yml.sh ./stub/gitea_yml.sh
./stub/nostr_yml.sh ./stub/nostr_yml.sh
# # start a browser session; point it to port 80 to ensure HTTPS redirect.
# # WWW_FQDN is in our certificate, so we resolve to that.
# wait-for-it -t 320 "$WWW_FQDN:80"
# wait-for-it -t 320 "$WWW_FQDN:443"
# # open bowser tabs.
# if [ "$DEPLOY_GHOST" = true ]; then
# xdg-open "http://$WWW_FQDN" > /dev/null 2>&1
# fi
# if [ "$DEPLOY_NEXTCLOUD" = true ]; then
# xdg-open "http://$NEXTCLOUD_FQDN" > /dev/null 2>&1
# fi
# if [ "$DEPLOY_GITEA" = true ]; then
# xdg-open "http://$GITEA_FQDN" > /dev/null 2>&1
# fi

View File

@ -37,15 +37,6 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do
if [ ! -d "$LOCAL_BACKUP_PATH" ]; then if [ ! -d "$LOCAL_BACKUP_PATH" ]; then
mkdir -p "$LOCAL_BACKUP_PATH" mkdir -p "$LOCAL_BACKUP_PATH"
fi fi
if [ "$RESTORE_WWW" = true ]; then
./restore_path.sh
fi
if [ "$BACKUP_APPS" = true ]; then
# if we're not restoring, then we may or may not back up.
./backup_path.sh
fi
done done
done done
done done