From fd3c7df9a95ae1895e4ccdbd4bd708efc23b2465 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Wed, 19 Sep 2018 16:30:18 -0600 Subject: [PATCH] Setup logging verbosity --- backup.log | 2 ++ backup.sh | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/backup.log b/backup.log index 7d29f3d..17c912f 100644 --- a/backup.log +++ b/backup.log @@ -1,3 +1,5 @@ [2018-09-19 16:00:05]-- Start backup.sh execution --- [2018-09-19 16:08:48] -- [ERROR] Script exited with code 2 -- This script MUST be run as ROOT. +[2018-09-19 16:21:08] -- [ERROR] Script exited with code 2 -- +This script MUST be run as ROOT. diff --git a/backup.sh b/backup.sh index def7898..e72fa2d 100755 --- a/backup.sh +++ b/backup.sh @@ -52,6 +52,11 @@ logFile="$scriptPath/${scriptName%.*}.log" # set script parameters to null and initialize array variables unset PARAMS +unset logLevel +unset logFileNormal +unset logFileVerbose +unset borgCreateParams +unset borgPruneParams errorExplain=() @@ -68,12 +73,20 @@ if [ -z $1 ]; then fi # use GetOpts to process parameters -while getopts ':l:' PARAMS; do +while getopts ':l:nv' PARAMS; do case "$PARAMS" in l) # use provided location for logFile logFile="${OPTARG}" ;; + n) + # standard logging (script errors, Borg summary) + logLevel="normal" + ;; + v) + # verbose logging (script errors, Borg details) + logLevel="verbose" + ;; ?) # unrecognized parameters trigger scriptHelp scriptHelp @@ -88,6 +101,20 @@ if [ $(id -u) -ne 0 ]; then fi +### Set logging verbosity based on invocation parameters +if [ "$logLevel" = "normal" ]; then + borgCreateParams='--stats' + borgPruneParams="--list" + unset logFileVerbose + logFileNormal="$logFile" +elif [ "$logLevel" = "verbose" ]; then + borgCreateParams='--list --stats' + borgPruneParams='--list' + logFileVerbose="$logFile" + unset logFileNormal +fi + + ### Log start of script operations echo -e "${bold}${stamp}-- Start $scriptName execution ---" >> "$logFile"