Compare commits
8 Commits
2b66d9e118
...
1c85071ca4
Author | SHA1 | Date |
---|---|---|
Asif Bacchus | 1c85071ca4 | |
Asif Bacchus | 6c8fc8bcdf | |
Asif Bacchus | 77d5b85ae3 | |
Asif Bacchus | c25348ddda | |
Asif Bacchus | 5e5e50b8e8 | |
Asif Bacchus | 78bdc0e5d6 | |
Asif Bacchus | 33416f8144 | |
Asif Bacchus | 87bfeb8464 |
114
backup_new.sh
114
backup_new.sh
|
@ -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
|
Loading…
Reference in New Issue