enclose timestamps in square brackets
This commit is contained in:
parent
3f1861fc01
commit
93bfdbfeb3
@ -53,32 +53,32 @@ cleanup () {
|
||||
if [ "$err503Copied" -eq 1 ]; then
|
||||
if ! rm -f "$webroot/$err503File" 2>>"$logFile"; then
|
||||
printf "${warn}[%s] -- [WARNING] Could not remove 503 error page." \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf " Web interface will not function until this file is " \
|
||||
>> "$logFile"
|
||||
printf "removed --${norm}\n" >> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
else
|
||||
printf "${cyan}[%s] -- [INFO] 503 error page removed --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
fi
|
||||
fi
|
||||
if [ "$sqlCopied" -eq 1 ]; then
|
||||
if ! rm -rf "$sqlDumpDir" 2>>"$logFile"; then
|
||||
printf "${warn}[%s] -- [WARNING] Could not remove temporary " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "SQL dump directory at %s. " "$sqlDumpDir" >> "$logFile"
|
||||
printf "Remove manually to free up space.${norm}\n" >> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
else
|
||||
printf "${cyan}[%s] -- [INFO] Temporary SQL dump directory " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "removed --${norm}\n" >> "$logFile"
|
||||
fi
|
||||
fi
|
||||
if [ "$offlineBackup" -eq 1 ]; then
|
||||
printf "${cyan}[%s] -- [INFO] Starting seafile services --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
seafSvc start
|
||||
fi
|
||||
}
|
||||
@ -86,11 +86,11 @@ cleanup () {
|
||||
# call cleanup and then exit with error report
|
||||
exitError () {
|
||||
printf "${err}[%s] -- [ERROR] %s: %s --${norm}\n" \
|
||||
"$(stamp)" "$1" "$2" >> "$logFile"
|
||||
"[$(stamp)]" "$1" "$2" >> "$logFile"
|
||||
cleanup
|
||||
# note script completion with error
|
||||
printf "${err}[%s] --- %s execution completed with error ---${norm}\n" \
|
||||
"$(stamp)" "$scriptName" >> "$logFile"
|
||||
"[$(stamp)]" "$scriptName" >> "$logFile"
|
||||
exit "$1"
|
||||
}
|
||||
|
||||
@ -178,26 +178,26 @@ seafSvc () {
|
||||
exitError 100 "Could not start ${seafService}"
|
||||
else
|
||||
printf "${cyan}[%s] -- [INFO] Started service: %s --${norm}\n" \
|
||||
"$(stamp)" "$seafService" >> "$logFile"
|
||||
"[$(stamp)]" "$seafService" >> "$logFile"
|
||||
fi
|
||||
if ! systemctl start "${seafHub}" >> "$logFile" 2>&1; then
|
||||
exitError 101 "Could not start ${seafHub}"
|
||||
else
|
||||
printf "${cyan}[%s] -- [INFO] Started service: %s --${norm}\n" \
|
||||
"$(stamp)" "$seafHub" >> "$logFile"
|
||||
"[$(stamp)]" "$seafHub" >> "$logFile"
|
||||
fi
|
||||
elif [ "$1" = "stop" ]; then
|
||||
if ! systemctl stop "${seafHub}" >> "$logFile" 2>&1; then
|
||||
exitError 103 "Could not stop ${seafHub}"
|
||||
else
|
||||
printf "${cyan}[%s] -- [INFO] Stopped service: %s --${norm}\n" \
|
||||
"$(stamp)" "$seafService" >> "$logFile"
|
||||
"[$(stamp)]" "$seafService" >> "$logFile"
|
||||
fi
|
||||
if ! systemctl stop "${seafService}" >> "$logFile" 2>&1; then
|
||||
exitError 102 "Could not stop ${seafService}"
|
||||
else
|
||||
printf "${cyan}[%s] -- [INFO] Stopped service: %s --${norm}\n" \
|
||||
"$(stamp)" "$seafHub" >> "$logFile"
|
||||
"[$(stamp)]" "$seafHub" >> "$logFile"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@ -210,11 +210,11 @@ stamp () {
|
||||
# same as exitError but for signal captures
|
||||
trapExit () {
|
||||
printf "${err}[%s] -- [ERROR] 99: Caught signal --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
cleanup
|
||||
# note script completion with error
|
||||
printf "${err}[%s] --- %s execution was terminated via signal ---${norm}\n" \
|
||||
"$(stamp)" "$scriptName" >> "$logFile"
|
||||
"[$(stamp)]" "$scriptName" >> "$logFile"
|
||||
exit 99
|
||||
}
|
||||
|
||||
@ -427,25 +427,25 @@ fi
|
||||
|
||||
### start logging
|
||||
printf "${magenta}[%s] --- Start %s execution ---${norm}\n" \
|
||||
"$(stamp)" "$scriptName" >> "$logFile"
|
||||
"[$(stamp)]" "$scriptName" >> "$logFile"
|
||||
printf "${cyan}[%s] -- [INFO] Log located at ${yellow}%s${cyan} --${norm}\n" \
|
||||
"$(stamp)" "$logFile" >> "$logFile"
|
||||
"[$(stamp)]" "$logFile" >> "$logFile"
|
||||
|
||||
|
||||
### 503 functionality
|
||||
if [ "$use503" -eq 1 ]; then
|
||||
printf "${cyan}[%s] -- [INFO] Copying 503 error page to " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "webroot -- ${norm}\n" >> "$logFile"
|
||||
if ! \cp --force "${err503Path}" "${webroot}/${err503File}" 2>> "$logFile"
|
||||
then
|
||||
printf "${warn}[%s] -- [WARNING] Failed to copy 503 error page. " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "Web users will NOT be notified --${norm}\n" >> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
else
|
||||
printf "${ok}[%s] -- [SUCCESS] 503 error page copied --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
# set cleanup flag
|
||||
err503Copied=1
|
||||
fi
|
||||
@ -455,7 +455,7 @@ fi
|
||||
### stop seahub and seafile service if offline backup requested
|
||||
if [ "$offlineBackup" -eq 1 ]; then
|
||||
printf "${cyan}[%s] -- [INFO] Stopping seafile services --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
seafSvc stop
|
||||
fi
|
||||
|
||||
@ -473,7 +473,7 @@ case "${configDetails}" in
|
||||
;;
|
||||
esac
|
||||
printf "${cyan}[%s] -- [INFO] ${yellow}%s${cyan} imported --${norm}\n" \
|
||||
"$(stamp)" "$configDetails" >> "$logFile"
|
||||
"[$(stamp)]" "$configDetails" >> "$logFile"
|
||||
|
||||
|
||||
### dump sql databases
|
||||
@ -499,7 +499,7 @@ fi
|
||||
|
||||
## create tmp directory and generate dumpfile names
|
||||
printf "${cyan}[%s] -- [INFO] Dumping SQL databases --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
# create temporary directory to dump files before borg backup
|
||||
if ! sqlDumpDir=$( mktemp -d 2>>"$logFile" ); then
|
||||
exitError 111 "Could not create temporary directory to dump SQL files"
|
||||
@ -507,7 +507,7 @@ fi
|
||||
# set cleanup flag
|
||||
sqlCopied=1
|
||||
printf "${cyan}[%s] -- [INFO] SQL dump files will be temporarily stored in:" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "\n${yellow}%s/${cyan} --${norm}\n" "$sqlDumpDir" >> "$logFile"
|
||||
# create unique names for database dump files
|
||||
sqlDump_ccnet="backup-$(date +%Y%m%d_%H%M%S)_${ccnetDB_name}.sql"
|
||||
@ -533,17 +533,17 @@ if ! mysqldump -h"${sqlServer}" -u"${sqlUser}" -p"${sqlPass}" \
|
||||
exitError 117 "Could not dump ${seahubDB_name} database"
|
||||
fi
|
||||
printf "${ok}[%s] -- [SUCCESS] SQL databases dumped successfully --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
|
||||
|
||||
### pre-backup tasks completed -- move to borg tasks
|
||||
printf "${ok}[%s] -- [SUCCESS] Pre-backup tasks completed --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
|
||||
|
||||
### Run borg variable checks
|
||||
printf "${cyan}[%s] -- [INFO] Verifying supplied borg details --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
|
||||
## verify borg base directory
|
||||
if [ -z "${borgBaseDir}" ]; then
|
||||
@ -635,7 +635,7 @@ if [ ! -d "${borgBaseDir}/tmp" ]; then
|
||||
exitError 132 "Unable to create borg ${borgBaseDir}/tmp directory"
|
||||
else
|
||||
printf "${cyan}[%s] -- [INFO] Created ${yellow}%s/tmp " \
|
||||
"$(stamp)" "${borgBaseDir}" >> "$logFile"
|
||||
"[$(stamp)]" "${borgBaseDir}" >> "$logFile"
|
||||
printf "${cyan}--${norm}\n" >> "$logFile"
|
||||
fi
|
||||
fi
|
||||
@ -668,18 +668,18 @@ fi
|
||||
|
||||
# execute borg
|
||||
printf "${cyan}[%s] -- [INFO] Executing borg backup operation --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
${borgCMD} 2>> "$logFile"
|
||||
borgResult="$?"
|
||||
|
||||
## check borg exit status
|
||||
if [ "$borgResult" -eq 0 ]; then
|
||||
printf "${ok}[%s] -- [SUCCESS] Borg backup completed " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "successfully --${norm}\n" >> "$logFile"
|
||||
elif [ "$borgResult" -eq 1 ]; then
|
||||
printf "${warn}[%s] -- [WARNING] Borg completed with warnings. " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "Review this logfile for details --${norm}\n" >> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
elif [ "$borgResult" -ge 2 ]; then
|
||||
@ -688,7 +688,7 @@ elif [ "$borgResult" -ge 2 ]; then
|
||||
exitError 138 "$err_1 $err_2"
|
||||
else
|
||||
printf "${warn}[%s] -- [WARNING] Borg exited with unknown return code. " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "Review this logfile for details --${norm}\n" >> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
fi
|
||||
@ -697,13 +697,13 @@ fi
|
||||
### execute borg prune if paramters are provided, otherwise skip with a warning
|
||||
if [ -n "${borgPruneSettings}" ]; then
|
||||
printf "${cyan}[%s] -- [INFO] Executing borg prune operation --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
borg prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \
|
||||
2>> "$logFile"
|
||||
borgPruneResult="$?"
|
||||
else
|
||||
printf "${warn}[%s] -- [WARNING] No prune parameters provided. " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "Your archive will continue growing with each backup --${norm}\n" \
|
||||
>> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
@ -713,10 +713,10 @@ fi
|
||||
if [ -n "${borgPruneResult}" ]; then
|
||||
if [ "${borgPruneResult}" -eq 0 ]; then
|
||||
printf "${ok}[%s] -- [SUCCESS] Borg prune completed --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
elif [ "$borgPruneResult" -eq 1 ]; then
|
||||
printf "${warn}[%s] -- [WARNING] Borg prune completed with warnings. " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "Review this logfile for details --${norm}\n" >> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
elif [ "$borgPruneResult" -ge 2 ]; then
|
||||
@ -725,7 +725,7 @@ if [ -n "${borgPruneResult}" ]; then
|
||||
exitError 139 "$err_1 $err_2"
|
||||
else
|
||||
printf "${warn}[%s] -- [WARNING] Borg prune exited with an unknown " \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "return code. Review this logfile for details --${norm}\n" \
|
||||
>> "$logFile"
|
||||
warnCount=$((warnCount+1))
|
||||
@ -737,16 +737,16 @@ fi
|
||||
|
||||
# note successful completion of borg commands
|
||||
printf "${ok}[%s] -- [SUCCESS] Backup operations completed --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
|
||||
# cleanup
|
||||
cleanup
|
||||
|
||||
# note complete success, tally warnings and exit
|
||||
printf "${ok}[%s] -- [SUCCESS] All processes completed --${norm}\n" \
|
||||
"$(stamp)" >> "$logFile"
|
||||
"[$(stamp)]" >> "$logFile"
|
||||
printf "${magenta}[%s] --- %s execution completed ---${norm}\n" \
|
||||
"$(stamp)" "$scriptName" >> "$logFile"
|
||||
"[$(stamp)]" "$scriptName" >> "$logFile"
|
||||
if [ "$warnCount" -gt 0 ]; then
|
||||
printf "${warn}%s warnings issued!${norm}\n" "${warnCount}" >> "$logFile"
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user