Setup logging verbosity
This commit is contained in:
parent
82496e238a
commit
fd3c7df9a9
@ -1,3 +1,5 @@
|
|||||||
[1m[2018-09-19 16:00:05]-- Start backup.sh execution ---
|
[1m[2018-09-19 16:00:05]-- Start backup.sh execution ---
|
||||||
[1m[31m[2018-09-19 16:08:48] -- [ERROR] Script exited with code 2 --[0m
|
[1m[31m[2018-09-19 16:08:48] -- [ERROR] Script exited with code 2 --[0m
|
||||||
[31mThis script MUST be run as ROOT.[0m
|
[31mThis script MUST be run as ROOT.[0m
|
||||||
|
[1m[31m[2018-09-19 16:21:08] -- [ERROR] Script exited with code 2 --[0m
|
||||||
|
[31mThis script MUST be run as ROOT.[0m
|
||||||
|
29
backup.sh
29
backup.sh
@ -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"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user