From eadba0bee9479cc2fef38650b9ba78be2cf37df7 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Mon, 8 Feb 2021 08:06:41 -0700 Subject: [PATCH] struct(RESTORE): add param processing --- backup/restore.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/backup/restore.sh b/backup/restore.sh index 01deaa6..8ebbdb9 100644 --- a/backup/restore.sh +++ b/backup/restore.sh @@ -130,6 +130,12 @@ scriptName="$(basename "$0")" configDetails="$scriptPath/${scriptName%.*}.details" errorCount=0 warnCount=0 +backupLocation="" +restoreMail=1 +restoreSQL=1 +restorePostfix=1 +restoreRedis=1 +restoreRspamd=1 # logfile default: same location and name as script but with '.log' extension logfile="$scriptPath/${scriptName%.*}.log" # mailcow/docker related @@ -146,10 +152,104 @@ fi ### process startup parameters while [ $# -gt 0 ]; do case "$1" in - -h | -\? | --help) + -h|-\?|--help) # display help scriptHelp ;; + -l|--log) + # set logfile location + if [ -z "$2" ]; then + consoleError '1' "Log file path cannot be null. Leave unspecified to save log in the same directory as this script." + fi + logfile="$2" + shift + ;; + -v|--verbose) + # set verbose logging from borg + borgParams='--list' + ;; + -c|--config|--details) + # location of configuration details file + if [ -n "$2" ]; then + if [ -f "$2" ]; then + configDetails=${2%/} + shift + else + consoleError '1' "$1: configuration file ($2) does not exist." + fi + else + consoleError '1' "$1: cannot be blank/empty." + fi + ;; + -d|--docker-compose) + # FULL path to docker-compose file + if [ -n "$2" ]; then + if [ -f "$2" ]; then + mcDockerCompose="$2" + shift + else + consoleError '1' "$1: cannot find docker-compose file as specified." + fi + else + consoleError '1' "$1: cannot be blank/empty." + fi + ;; + -m|--mailcow-config) + # FULL path to mailcow configuration file file + if [ -n "$2" ]; then + if [ -f "$2" ]; then + mcConfig="$2" + shift + else + consoleError '1' "$1: cannot find mailcow configuration file as specified." + fi + else + consoleError '1' "$1: cannot be blank/empty." + fi + ;; + -t1|--timeout-start) + if [ -z "$2" ]; then + consoleError '1' "$1: cannot be blank/empty." + else + dockerStartTimeout="$2" + shift + fi + ;; + -t2|--timeout-stop) + if [ -z "$2" ]; then + consoleError '1' "$1: cannot be blank/empty." + else + dockerStopTimeout="$2" + shift + fi + ;; + -b|--backup-location) + if [ -n "$2" ]; then + if [ -d "$2" ] && [ -n "$( ls -A "$2" )" ]; then + backupLocation="$2" + shift + else + consoleError '1' "$1: cannot find specified backup location directory or it is empty." + fi + else + consoleError '1' "$1: cannot be blank/empty." + fi + ;; + --skip-mail) + restoreMail=0 + ;; + --skip-sql) + restoreSQL=0 + ;; + --skip-postfix) + restorePostfix=0 + ;; + --skip-redis) + restoreRedis=0 + ;; + --skip-rspamd) + restoreRspamd=0 + ;; *) printf "\n%Unknown option: %s\n" "$err" "$1" printf "Use '--help' for valid options.%s\n\n" "$norm"