Compare commits

...

8 Commits

Author SHA1 Message Date
Asif Bacchus 1c85071ca4 export borg remote location env var 2019-05-27 05:31:08 -06:00
Asif Bacchus 6c8fc8bcdf add user notification for starting borg backup 2019-05-27 05:25:47 -06:00
Asif Bacchus 77d5b85ae3 fix typo in warning message 2019-05-27 05:24:47 -06:00
Asif Bacchus c25348ddda split long error messages into separate vars 2019-05-27 05:24:26 -06:00
Asif Bacchus 5e5e50b8e8 execute borg prune and report results 2019-05-27 05:08:09 -06:00
Asif Bacchus 78bdc0e5d6 check borg return codes 2019-05-27 04:31:21 -06:00
Asif Bacchus 33416f8144 execute borg 2019-05-27 04:19:21 -06:00
Asif Bacchus 87bfeb8464 create borg tmp dir 2019-05-27 03:53:43 -06:00
1 changed files with 113 additions and 1 deletions

View File

@ -464,6 +464,9 @@ else
export BORG_PASSPHRASE="DummyPasswordSoBorgFails"
fi
## export borg remote path, if specified
if [ -n "${borgRemote}" ]; then export BORG_REMOTE_PATH="${borgRemote}"; fi
## read additional files
if [ -n "${borgXtraListPath}" ]; then
# check if file actually exists
@ -495,6 +498,113 @@ exclusions=1
fi
### create borg temp dir:
## python requires a writable temporary directory when unpacking borg and
## executing commands. This defaults to /tmp but many systems mount /tmp with
## the 'noexec' option for security. Thus, we will use/create a 'tmp' folder
## within the BORG_BASE_DIR and instruct python to use that instead of /tmp
# check if BORG_BASE_DIR/tmp exists, if not, create it
if [ ! -d "${borgBaseDir}/tmp" ]; then
if ! mkdir "${borgBaseDir}/tmp"; then
exitError 132 "Unable to create borg ${borgBaseDir}/tmp directory"
else
printf "${cyan}[%s] -- [INFO] Created ${yellow}%s/tmp " \
"$(stamp)" "${borgBaseDir}" >> "$logFile"
printf "${cyan}--${norm}\n" >> "$logFile"
fi
fi
export TMPDIR="${borgBaseDir}/tmp"
### execute borg depending on whether extra files and/or exclusions are defined
## construct the proper borg commandline
# base command
if [ "$exclusions" -eq 0 ]; then
borgCMD="borg --show-rc create ${borgCreateParams} \
::$(date +%Y-%m-%d_%H%M%S) \
${seafDir} \
${seafData} \
${sqlDumpDir}"
elif [ "$exclusions" -eq 1 ]; then
borgCMD="borg --show-rc create ${borgCreateParams} \
--exclude-from ${borgExcludeListPath} \
::$(date +%Y-%m-%d_%H%M%S) \
${seafDir} \
${seafData} \
${sqlDumpDir}"
fi
# add extra locations if defined
if [ "$includeXtra" -eq 1 ]; then
borgCMD="${borgCMD} ${xtraList}"
fi
# execute borg
printf "${cyan}[%s] -- [INFO] Executing borg backup operation --${norm}\n" \
"$(stamp)" >> "$logFile"
${borgCMD} 2>> "$logFile"
borgResult="$?"
## check borg exit status
if [ "$borgResult" -eq 0 ]; then
printf "${ok}[%s] -- [SUCCESS] Borg backup completed " \
"$(stamp)" >> "$logFile"
printf "successfully --${norm}\n" >> "$logFile"
elif [ "$borgResult" -eq 1 ]; then
printf "${warn}[%s] -- [WARNING] Borg completed with warnings. " \
"$(stamp)" >> "$logFile"
printf "Review this logfile for details --${norm}\n" >> "$logFile"
elif [ "$borgResult" -ge 2 ]; then
err_1="Borg exited with a critical error. Please review this log file"
err_2="for details."
exitError 138 "$err_1 $err_2"
else
printf "${warn}[%s] -- [WARNING] Borg exited with unknown return code. " \
"$(stamp)" >> "$logFile"
printf "Review this logfile for details --${norm}\n" >> "$logFile"
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"
borg prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \
2>> "$logFile"
borgPruneResult="$?"
else
printf "${warn}[%s] -- [WARNING] No prune parameters provided. " \
"$(stamp)" >> "$logFile"
printf "Your archive will continue growing with each backup --${norm}\n" \
>> "$logFile"
fi
## report on prune operation if executed
if [ -n "${borgPruneResult}" ]; then
if [ "${borgPruneResult}" -eq 0 ]; then
printf "${ok}[%s] -- [SUCCESS] Borg prune completed --${norm}\n" \
"$(stamp)" >> "$logFile"
elif [ "$borgPruneResult" -eq 1 ]; then
printf "${warn}[%s] -- [WARNING] Borg prune completed with warnings. " \
"$(stamp)" >> "$logFile"
printf "Review this logfile for details --${norm}\n" >> "$logFile"
elif [ "$borgPruneResult" -ge 2 ]; then
err_1="Borg prune exited with a critical error. Please review this"
err_2="log file for details."
exitError 139 "$err_1 $err_2"
else
printf "${warn}[%s] -- [WARNING] Borg prune exited with an unknown " \
"$(stamp)" >> "$logFile"
printf "return code. Review this logfile for details --${norm}\n" \
>> "$logFile"
fi
fi
@ -514,4 +624,6 @@ exit 0
# 116: could not dump SEAFILE-DB
# 117: could not dump SEAHUB-DB
# 130: null borg configuration variable
# 131: invalid borg configuration variable
# 131: invalid borg configuration variable
# 138: borg exited with a critical error
# 139: borg prune exited with a critical error