Compare commits
9 Commits
1e217bf88c
...
71507b1341
Author | SHA1 | Date |
---|---|---|
Asif Bacchus | 71507b1341 | |
Asif Bacchus | 5cde95687e | |
Asif Bacchus | 0d1e85179a | |
Asif Bacchus | aca45311ea | |
Asif Bacchus | 0d018e3b65 | |
Asif Bacchus | 2323eb435e | |
Asif Bacchus | e7f5a836ec | |
Asif Bacchus | fc3c793dc2 | |
Asif Bacchus | 15bf15269d |
|
@ -11,7 +11,7 @@ ok="\e[32m"
|
|||
lit="\e[93m"
|
||||
op="\e[39m"
|
||||
info="\e[96m"
|
||||
note="\e[35m"
|
||||
note="\e[95m"
|
||||
stamp="[`date +%Y-%m-%d` `date +%H:%M:%S`]"
|
||||
|
||||
|
||||
|
@ -166,7 +166,7 @@ function cleanup {
|
|||
|
||||
## remove 503 error page
|
||||
# check value of 'clean503' to see if this is necessary (=1) otherwise, skip
|
||||
if [ "$clean503" -eq 1 ]; then
|
||||
if [ "$clean503" = "1" ]; then
|
||||
# proceed with cleanup
|
||||
echo -e "${op}${stamp} Removing 503 error page..." >> "$logFile"
|
||||
rm -f "$webroot/$err503File" >> "$logFile" 2>&1
|
||||
|
@ -241,6 +241,7 @@ unset BORG_RSH
|
|||
unset BORG_REPO
|
||||
unset BORG_PASSPHRASE
|
||||
unset BORG_REMOTE_PATH
|
||||
unset TMPDIR
|
||||
exitError=()
|
||||
errorExplain=()
|
||||
exitWarn=()
|
||||
|
@ -255,6 +256,7 @@ errorExplain[200]="Could not dump NextCloud SQL database"
|
|||
errorExplain[210]="Invalid or non-existant borg base directory specified (borg backup details file)"
|
||||
errorExplain[211]="Invalid or non-existant path to borg SSH keyfile (borg backup details file)"
|
||||
errorExplain[212]="Name of borg repo was not specified (borg backup details file)"
|
||||
errorExplain[215]="Could not find/create 'tmp' directory within borg base directory. Please manually create it and ensure it's writable"
|
||||
errorExplain[220]="Borg exited with a critical error. Please check this script's logfile for details"
|
||||
errorExplain[221]="Borg prune exited with ERRORS. Please check this script's logfile for details"
|
||||
|
||||
|
@ -271,6 +273,7 @@ warningExplain[2112]="No remote borg instance specified. Operations will be slow
|
|||
warningExplain[2113]="The specified file containing extra files for inclusion in borgbackup could not be found"
|
||||
warningExplain[2114]="The specified file containing exclusion patterns for borgbackup could not be found. Backup was performed as though NO exclusions were defined"
|
||||
warningExplain[2115]="No paramters provided for borg prune. No repo pruning has taken place. You should reconsider this decision to control the size/history of your backups"
|
||||
warningExplain[2116]="No additional locations are specified for inclusion in backup. ONLY NextCloud DATA will be backed up (no configuration, etc). If this is unintentional, check the inclusion file referenced in your borgbackup settings"
|
||||
warningExplain[2200]="Borg completed with warnings. Please check this script's logfile for details"
|
||||
warningExplain[2201]="Borg exited with an unknown return-code. Please check this script's logfile for details"
|
||||
warningExplain[2210]="Borg prune exited with warnings. Please check this script's logfile for details"
|
||||
|
@ -556,7 +559,7 @@ else
|
|||
quit
|
||||
fi
|
||||
echo -e "${op}${stamp} Borg base dir... OK${normal}" >> "$logFile"
|
||||
export BORG_BASE_DIR="${borgConfig[0]}"
|
||||
export BORG_BASE_DIR="${borgConfig[0]%/}"
|
||||
fi
|
||||
# check: path to SSH keyfile
|
||||
if [ -z "${borgConfig[1]}" ]; then
|
||||
|
@ -581,10 +584,12 @@ if [ -z "${borgConfig[2]}" ]; then
|
|||
cleanup
|
||||
quit
|
||||
else
|
||||
echo -e "${op}${stamp} Borg REPO name... OK${normal}" >> "$logFile"
|
||||
export BORG_REPO="${borgConfig[2]}"
|
||||
fi
|
||||
# repo password
|
||||
if [ -n "${borgConfig[3]}" ]; then
|
||||
echo -e "${op}${stamp} Borg SSH/REPO password... OK${normal}" >> "$logFile"
|
||||
export BORG_PASSPHRASE="${borgConfig[3]}"
|
||||
else
|
||||
exitWarn+=('2111')
|
||||
|
@ -600,6 +605,7 @@ borgExclude="${borgConfig[5]}"
|
|||
borgPrune="${borgConfig[6]}"
|
||||
# export: borg remote path (if not blank)
|
||||
if [ -n "${borgConfig[7]}" ]; then
|
||||
echo -e "${op}${stamp} Borg REMOTE path... OK${normal}" >> "$logFile"
|
||||
export BORG_REMOTE_PATH="${borgConfig[7]}"
|
||||
else
|
||||
exitWarn+=('2112')
|
||||
|
@ -619,20 +625,68 @@ if [ -n "$borgXtra" ]; then
|
|||
else
|
||||
exitWarn+=('2113')
|
||||
fi
|
||||
else
|
||||
# no extra locations specified
|
||||
echo -e "${op}${stamp} No additional locations specified for backup." \
|
||||
"Only NextCloud data files will be backed up${normal}" >> "$logFile"
|
||||
exitWarn+=('2116')
|
||||
fi
|
||||
|
||||
## Check if borgExclude exists since borg will throw an error if it's missing
|
||||
checkExist ff "$borgExclude"
|
||||
checkResult="$?"
|
||||
if [ "$checkResult" = "0" ]; then
|
||||
echo -e "${op}${stamp} Found ${lit}${borgExclude}${normal}" \
|
||||
>> "$logFile"
|
||||
if [ -n "$borgExclude" ]; then
|
||||
checkExist ff "$borgExclude"
|
||||
checkResult="$?"
|
||||
if [ "$checkResult" = "0" ]; then
|
||||
echo -e "${op}${stamp} Found ${lit}${borgExclude}${normal}" \
|
||||
>> "$logFile"
|
||||
else
|
||||
# file not found, unset the variable so it's like it was not specified
|
||||
# in the first place and continue with backup
|
||||
unset borgExclude
|
||||
exitWarn+=('2114')
|
||||
fi
|
||||
else
|
||||
echo -e "${op}${stamp} Exclusion pattern file not specified." \
|
||||
"No exclusions will be processed${normal}" >> "$logFile"
|
||||
fi
|
||||
|
||||
|
||||
## Export TMPDIR environment variable for borg via python
|
||||
## 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
|
||||
echo -e "${op}${stamp} Checking for tmp directory at ${lit}${BORG_BASE_DIR}" \
|
||||
"${normal}" >> "$logFile"
|
||||
checkExist fd "$BORG_BASE_DIR/tmp"
|
||||
checkResult="$?"
|
||||
if [ "$checkResult" = "1" ]; then
|
||||
# folder not found
|
||||
echo -e "${op}${stamp} tmp folder not found... creating${lit}" \
|
||||
"${BORG_BASE_DIR}/tmp${normal}" >> "$logFile"
|
||||
mkdir "$BORG_BASE_DIR/tmp" 2>> "$logFile"
|
||||
# verify folder created
|
||||
checkExist fd "$BORG_BASE_DIR/tmp"
|
||||
checkResult="$?"
|
||||
if [ "$checkResult" = "0" ]; then
|
||||
# folder exists
|
||||
echo -e "${op}${stamp} tmp folder created within borg base directory" \
|
||||
"${normal}" >> "$logFile"
|
||||
else
|
||||
# problem creating folder and script will exit
|
||||
exitError+=('215')
|
||||
cleanup
|
||||
quit
|
||||
fi
|
||||
else
|
||||
# folder found
|
||||
echo -e "${op}${stamp} tmp folder found within borg base directory" \
|
||||
"${normal}" >> "$logFile"
|
||||
fi
|
||||
# export TMPDIR environment variable
|
||||
export TMPDIR="${BORG_BASE_DIR}/tmp"
|
||||
|
||||
|
||||
## Generate and execute borg
|
||||
# commandline depends on whether borgExclude is empty or not
|
||||
|
|
Loading…
Reference in New Issue