Setup logging verbosity

This commit is contained in:
Asif Bacchus 2018-09-19 16:30:18 -06:00
parent 82496e238a
commit fd3c7df9a9
2 changed files with 30 additions and 1 deletions

View File

@ -1,3 +1,5 @@
[2018-09-19 16:00:05]-- Start backup.sh execution --- [2018-09-19 16:00:05]-- Start backup.sh execution ---
[2018-09-19 16:08:48] -- [ERROR] Script exited with code 2 -- [2018-09-19 16:08:48] -- [ERROR] Script exited with code 2 --
This script MUST be run as ROOT. 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.

View File

@ -52,6 +52,11 @@ logFile="$scriptPath/${scriptName%.*}.log"
# set script parameters to null and initialize array variables # set script parameters to null and initialize array variables
unset PARAMS unset PARAMS
unset logLevel
unset logFileNormal
unset logFileVerbose
unset borgCreateParams
unset borgPruneParams
errorExplain=() errorExplain=()
@ -68,12 +73,20 @@ if [ -z $1 ]; then
fi fi
# use GetOpts to process parameters # use GetOpts to process parameters
while getopts ':l:' PARAMS; do while getopts ':l:nv' PARAMS; do
case "$PARAMS" in case "$PARAMS" in
l) l)
# use provided location for logFile # use provided location for logFile
logFile="${OPTARG}" logFile="${OPTARG}"
;; ;;
n)
# standard logging (script errors, Borg summary)
logLevel="normal"
;;
v)
# verbose logging (script errors, Borg details)
logLevel="verbose"
;;
?) ?)
# unrecognized parameters trigger scriptHelp # unrecognized parameters trigger scriptHelp
scriptHelp scriptHelp
@ -88,6 +101,20 @@ if [ $(id -u) -ne 0 ]; then
fi 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 ### Log start of script operations
echo -e "${bold}${stamp}-- Start $scriptName execution ---" >> "$logFile" echo -e "${bold}${stamp}-- Start $scriptName execution ---" >> "$logFile"