func cleanup to remove script working files

This commit is contained in:
Asif Bacchus 2019-05-25 12:33:35 -06:00
parent e85aa37553
commit 08ab44ce84

View File

@ -34,9 +34,32 @@ badParam () {
fi
}
# cleanup
cleanup () {
# cleanup 503 if copied
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"
printf " Web interface will not function until this file is " \
>> "$logFile"
printf "removed --${norm}\n" >> "$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"
printf "SQL dump directory at $sqlDumpDir. " >> "$logFile"
printf "Remove manually to free up space.${norm}\n" >> "$logFile"
fi
fi
}
exitError () {
printf "${err}[%s] -- [ERROR] %s: %s --${norm}\n" \
"$(stamp)" "$1" "$2" >> "$logFile"
cleanup
exit "$1"
}
@ -79,6 +102,8 @@ logFile="$scriptPath/${scriptName%.*}.log"
borgCreateParams='--stats'
borgPruneParams='--list'
configDetails="$scriptPath/seafbackup.details"
err503Copied=0
sqlCopied=0
# 503 related
use503=0
@ -286,6 +311,8 @@ if [ $use503 -eq 1 ]; then
else
printf "${ok}[%s] -- [SUCCESS] 503 error page copied --${norm}\n" \
"$(stamp)" >> "$logFile"
# set cleanup flag
err503Copied=1
fi
fi
@ -348,7 +375,8 @@ if ! mysqldump -h"${sqlServer}" -u"${sqlUser}" -p"${sqlPass}" \
fi
printf "${ok}[%s] -- [SUCCESS] SQL databases dumped successfully --${norm}\n" \
"$(stamp)" >> "$logFile"
# set cleanup flag
sqlCopied=1