From 4aae61f97ecbaca55293d658973540af47d64bc7 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Mon, 8 Mar 2021 00:36:32 -0700 Subject: [PATCH] feature(BACKUP): allow non-default borg location - parameter to specify non-default borg program location Closes github #10 --- backup/backup.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/backup/backup.sh b/backup/backup.sh index f3e2fa3..a7881c2 100755 --- a/backup/backup.sh +++ b/backup/backup.sh @@ -153,6 +153,10 @@ scriptHelp() { newline textblock "${magenta}--- script related parameters ---${norm}" newline + switchTextblock "-b | --borg" + textblock "FULL path to borg executable file if not in the default location." + defaultsTextblock "(/usr/bin/borg)" + newline switchTextblock "-c | --config | --details" textblock "Path to the configuration key/value-pair file for this script." defaultsTextblock "(scriptPath/scriptName.details)" @@ -262,6 +266,7 @@ configDetails="$scriptPath/${scriptName%.*}.details" err503Copied=0 sqlDumpDirCreated=0 exclusions=0 +borgPath="/usr/bin/borg" # borg output verbosity -- normal borgCreateParams='--stats' borgPruneParams='--list' @@ -300,6 +305,15 @@ while [ $# -gt 0 ]; do # do NOT colourize log file colourizeLogFile=0 ;; + -b|--borg) + # specify non-default borg path + if [ -n "$2" ]; then + borgPath="${2%/}" + shift + else + badParam empty "$@" + fi + ;; -c|--config|--details) # location of config details file if [ -n "$2" ]; then @@ -421,8 +435,8 @@ if [ ! -f "$configDetails" ]; then badParam dne "(--details default)" "$configDetails" fi # is borg installed? -if ! command -v borg > /dev/null; then - printf "\n%sERROR: BORG is not installed on this system!%s\n\n" "$err" "$norm" +if ! find "$borgPath" -type f -executable > /dev/null 2>&1; then + printf "\n%sERROR: BORG cannot be found in the specified or default location on this system!%s\n\n" "$err" "$norm" exit 3 fi # if 503 functionality is enabled, do 503 related files exist? @@ -719,7 +733,7 @@ printf "%s[%s] -- [INFO] Pre-backup tasks completed, calling borgbackup --%s\n" ## construct the proper borg commandline # base command if [ "$exclusions" -eq 0 ]; then - borgCMD="borg create --show-rc ${borgCreateParams} \ + borgCMD="${borgPath} create --show-rc ${borgCreateParams} \ ::$(date +%Y-%m-%d_%H%M%S) \ ${mcConfig%/*} \ ${sqlDumpDir} \ @@ -730,7 +744,7 @@ if [ "$exclusions" -eq 0 ]; then ${dockerVolumeCrypt} \ ${xtraList}" elif [ "$exclusions" -eq 1 ]; then - borgCMD="borg create --show-rc ${borgCreateParams} \ + borgCMD="${borgPath} create --show-rc ${borgCreateParams} \ --exclude-from ${borgExcludeListPath} \ ::$(date +%Y-%m-%d_%H%M%S) \ ${mcConfig%/*} \ @@ -774,7 +788,7 @@ fi if [ -n "${borgPruneSettings}" ]; then printf "%s[%s] -- [INFO] Executing borg prune operation --%s\n" \ "$cyan" "$(stamp)" "$norm" >> "$logFile" - borg prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \ + "${borgPath}" prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \ 2>> "$logFile" borgPruneResult="$?" else