From 3897d6f3c3cbebe599e2d7a417f412e8cb63f384 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Fri, 17 Oct 2025 13:50:02 -0700 Subject: [PATCH] Add parameters and usage function to backup script. --- bin/backup.sh | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/bin/backup.sh b/bin/backup.sh index 3037a35..8293bd2 100755 --- a/bin/backup.sh +++ b/bin/backup.sh @@ -16,6 +16,39 @@ BASENAME="Backup" file="$BACKUP_DIR/$BASENAME.$DATE.$HOSTNAME.$TAG.zip" time="`which time`" +## Functions ## + +function usage { + cat <<- EOF + Backup script for Hyperling's self-managed Docker setup. + + Usage: $PROG [-u] [-d] [-h] + -u : Bring all containers up after the backup has finished. + -d : Bring all containers down before taking the backup. + -h : Display this help text. + + Example: + $PROG -ud + EOF + + exit $1 +} + +## Parameters ## + +up=FALSE +down=FALSE + +while getopts ':udh' opt; do + case "$opt" in + u) up=TRUE ;; + d) down=TRUE ;; + h) usage 0 ;; + *) echo "ERROR: Option $OPTARG not recognized." >&2 + usage 1 ;; + esac +done + ## Main ## # Ensure backup directory exists with correct permissions. @@ -30,8 +63,10 @@ cd "$BACKUP_DIR" mv -v "$BASENAME"*"$TAG"* TRASH/ rm -v TRASH/* -echo -e "\n`date` - Take down services for a cold backup." -manage.sh -d +if [[ "$down" == "TRUE" ]]; then + echo -e "\n`date` - Take down services for a cold backup." + manage.sh -d +fi echo -e "\n`date` - Create the backup for '$DOCKER_HOME'." $time zip -r $file.tmp \ @@ -46,8 +81,10 @@ ls -sh $file echo -e "\n`date` - Ensure other users can access the file." chmod -v 755 $file -echo -e "\n`date` - Bring services back up." -manage.sh -u +if [[ "$up" == "TRUE" ]]; then + echo -e "\n`date` - Bring services back up." + manage.sh -u +fi ## Finish ##