Compare commits

...

10 Commits

Author SHA1 Message Date
Asif Bacchus 0fcab85da9 fix incorrect filename 2019-07-30 01:11:15 -06:00
Asif Bacchus ed62bb1e38 update logwatch integration 2019-07-30 00:44:37 -06:00
Asif Bacchus 3a759f39ac reworded redundant success msgs 2019-07-30 00:41:02 -06:00
Asif Bacchus 5cd023010c update wiki link, match details filename to script 2019-07-30 00:39:17 -06:00
Asif Bacchus 8e30cb4048 fix timestamp double-bracket 2019-07-26 03:16:55 -06:00
Asif Bacchus 8edd833544 fix final success msg output spacing err 2019-07-26 03:15:26 -06:00
Asif Bacchus dd49378678 check running as root 2019-07-26 03:14:12 -06:00
Asif Bacchus efe202d9a3 new directory structure 2019-07-26 03:11:53 -06:00
Asif Bacchus 9936cf7de3 add link to wiki 2019-07-20 18:14:14 -06:00
Asif Bacchus 0b1d220b5b update readme and license 2019-07-20 18:09:19 -06:00
11 changed files with 113 additions and 54 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) <year> <copyright holders> Copyright (c) 2019 Asif Bacchus
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+61 -5
View File
@@ -1,7 +1,63 @@
# seafileBackup # Backup a bare-metal Seafile installation using borgbackup <!-- omit in toc -->
Backup Seafile DB and data using borgbackup to rsync.net Simple POSIX-compliant script to backup a bare-metal Seafile installation using borgbackup to a remote SSH-capable storage system. I strongly suggest using rsync.net since they are very reliable, fast and even have special pricing for people using borgbackup/attic [(details here)](https://www.rsync.net/products/attic.html).
This readme will be an overiew of the purpose of the repo and BASIC usability **THIS SCRIPT USES BORG [(borgbackup)](https://borgbackup.readthedocs.io/en/stable/) SO PLEASE ENSURE THAT IS INSTALLED CORRECTLY BEFORE TRYING TO USE THIS SCRIPT!**
information. Detailed usage information will all be presented in the repo's
wiki. - [Basic features of this script:](#Basic-features-of-this-script)
- [Check out the wiki](#Check-out-the-wiki)
- [Overview](#Overview)
- [Installation](#Installation)
- [Running the script](#Running-the-script)
- [*seafbackup.sh*](#seafbackupsh)
- [Final thoughts](#Final-thoughts)
## Basic features of this script:
- Backup your entire Seafile program and data directories.
- Dump Seafile SQL databases to a temporary directory, add them to the backup and then remove the temporary directory.
- Easily add additional directories/files to the backup by modifying a plain-text file.
- Easily exclude directories/files from being backed up (i.e. thumbnails) by modifying a plain-text file.
- Optionally stop Seafile services during the backup and restart them after.
- Optionally copy a 503 error page to your webserver so users know your server is unavailable due to a backup being performed. The 503 file is removed when the backup is completed.
- Run 'borg prune' to trim old backups according to your schedule so you don't pay storage fees for super-old or un-needed backups.
- Create a clear, easy to parse log file so you can keep an eye on warnings/errors, etc.
- The generated log file can be easily parsed by tools like *logwatch* so you can integrate backup-monitoring with your existing system-monitoring solutions.
## Check out the wiki
This readme is an overview of the script. For detailed instructions on how the script works, what it does and it's various options, please [read the wiki](https://git.asifbacchus.app/asif/seafileBackup/wiki)! I've tried to annotate the files as best I could with many many comments, but seriously, reading the [wiki](https://git.asifbacchus.app/asif/seafileBackup/wiki) if you're stuck is the best approach since I try to go over everything step-by-step.
## Overview
This script has NO mandatory parameters. If no parameters are specified, it will proceed using defaults which normally align with the recommended Seafile installation defaults. That being said, it is impossible to determine defaults for things like your backup-server settings, so please make sure you customize the *seafbackup.details* file with appropriate details!
By default, the script will dump Seafile SQL databases and back them up along with your entire Seafile program and data directories. You can add additional files to be backed up by adding paths to *xtraLocations.borg*.
## Installation
Simply clone this repo to the desired location. I recommend somewhere simple like *ROOT's home directory* so any sensitive information is restricted to the root user by default.
```bash
cd /root
sudo git clone https://git.asifbacchus.app/asif/seafileBackup.git
```
## Running the script
```bash
./seafbackup.sh [parameters]
# display abbreviated help
./seafbackup.sh --help
```
## *seafbackup.sh*
Please open this file in a text editor and follow the comments to fill in the parameters with the correct values for your environment and your backup server.
## Final thoughts
I hope this makes backing up your Seafile server easier and removes one more mundane administrative task from your schedule :-) If you have any comments, questions, concerns, suggestions for improvements or notice any bugs, please file an issue in this repo!
For more scripts and solutions like this, check out my blog at [My Techie-Thoughts](https://mytechiethoughts.com). Thanks!
@@ -1,9 +1,9 @@
# Location of your script's log file, -l parameter # Location of your script's log file, -l parameter
LogFile = /path/to/your/backup.log LogFile = /path/to/your/seafbackup.log
# Format of logrotate archives for your script. Example assumes compression and # Format of logrotate archives for your script. Example assumes compression and
# extension preservation # extension preservation
Archive = /path/to/your/logfile.ext.?.gz Archive = /path/to/your/seafbackup.log.?.gz
# Apply the correct date/time filtering to match the format of the script's log # Apply the correct date/time filtering to match the format of the script's log
# We are using a custom pl script in /etc/logwatch/scripts/shared/ You don't # We are using a custom pl script in /etc/logwatch/scripts/shared/ You don't
@@ -1,5 +1,5 @@
# Name of the logfile group without any extension # Name of the logfile group without any extension
LogFile = backup LogFile = seafbackup
# Heading displayed on Logwatch's report for this service # Heading displayed on Logwatch's report for this service
Title = "System and Seafile Backup" Title = "System and Seafile Backup"
@@ -34,7 +34,7 @@ if ($detailLevel == 0) {
elsif ($ThisLine =~ /\-- \[WARNING\] /) { elsif ($ThisLine =~ /\-- \[WARNING\] /) {
$summaryWarn++; $summaryWarn++;
} }
elsif ($ThisLine =~ /All processes completed successfully/) { elsif ($ThisLine =~ /All processes completed/) {
$summarySuccess++; $summarySuccess++;
} }
} }
+47 -44
View File
@@ -53,32 +53,32 @@ cleanup () {
if [ "$err503Copied" -eq 1 ]; then if [ "$err503Copied" -eq 1 ]; then
if ! rm -f "$webroot/$err503File" 2>>"$logFile"; then if ! rm -f "$webroot/$err503File" 2>>"$logFile"; then
printf "${warn}[%s] -- [WARNING] Could not remove 503 error page." \ printf "${warn}[%s] -- [WARNING] Could not remove 503 error page." \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf " Web interface will not function until this file is " \ printf " Web interface will not function until this file is " \
>> "$logFile" >> "$logFile"
printf "removed --${norm}\n" >> "$logFile" printf "removed --${norm}\n" >> "$logFile"
warnCount=$((warnCount+1)) warnCount=$((warnCount+1))
else else
printf "${cyan}[%s] -- [INFO] 503 error page removed --${norm}\n" \ printf "${cyan}[%s] -- [INFO] 503 error page removed --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
fi fi
fi fi
if [ "$sqlCopied" -eq 1 ]; then if [ "$sqlCopied" -eq 1 ]; then
if ! rm -rf "$sqlDumpDir" 2>>"$logFile"; then if ! rm -rf "$sqlDumpDir" 2>>"$logFile"; then
printf "${warn}[%s] -- [WARNING] Could not remove temporary " \ printf "${warn}[%s] -- [WARNING] Could not remove temporary " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "SQL dump directory at %s. " "$sqlDumpDir" >> "$logFile" printf "SQL dump directory at %s. " "$sqlDumpDir" >> "$logFile"
printf "Remove manually to free up space.${norm}\n" >> "$logFile" printf "Remove manually to free up space.${norm}\n" >> "$logFile"
warnCount=$((warnCount+1)) warnCount=$((warnCount+1))
else else
printf "${cyan}[%s] -- [INFO] Temporary SQL dump directory " \ printf "${cyan}[%s] -- [INFO] Temporary SQL dump directory " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "removed --${norm}\n" >> "$logFile" printf "removed --${norm}\n" >> "$logFile"
fi fi
fi fi
if [ "$offlineBackup" -eq 1 ]; then if [ "$offlineBackup" -eq 1 ]; then
printf "${cyan}[%s] -- [INFO] Starting seafile services --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Starting seafile services --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
seafSvc start seafSvc start
fi fi
} }
@@ -86,11 +86,11 @@ cleanup () {
# call cleanup and then exit with error report # call cleanup and then exit with error report
exitError () { exitError () {
printf "${err}[%s] -- [ERROR] %s: %s --${norm}\n" \ printf "${err}[%s] -- [ERROR] %s: %s --${norm}\n" \
"[$(stamp)]" "$1" "$2" >> "$logFile" "$(stamp)" "$1" "$2" >> "$logFile"
cleanup cleanup
# note script completion with error # note script completion with error
printf "${err}[%s] --- %s execution completed with error ---${norm}\n" \ printf "${err}[%s] --- %s execution completed with error ---${norm}\n" \
"[$(stamp)]" "$scriptName" >> "$logFile" "$(stamp)" "$scriptName" >> "$logFile"
exit "$1" exit "$1"
} }
@@ -165,9 +165,8 @@ scriptHelp () {
printf "More details and examples of script usage can be found in the " printf "More details and examples of script usage can be found in the "
printf "repo wiki at\n" printf "repo wiki at\n"
printf "${yellow}https://git.asifbacchus.app/asif/seafileBackup.git" printf "${yellow}https://git.asifbacchus.app/BacchusGroup/seafileBackup"
printf "/wiki${norm}.\n" printf "/wiki${norm}.\n"
printf "${cyan}%s${norm}\n\n" "--------------------------------------------------------------------------------" printf "${cyan}%s${norm}\n\n" "--------------------------------------------------------------------------------"
} }
@@ -178,26 +177,26 @@ seafSvc () {
exitError 100 "Could not start ${seafService}" exitError 100 "Could not start ${seafService}"
else else
printf "${cyan}[%s] -- [INFO] Started service: %s --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Started service: %s --${norm}\n" \
"[$(stamp)]" "$seafService" >> "$logFile" "$(stamp)" "$seafService" >> "$logFile"
fi fi
if ! systemctl start "${seafHub}" >> "$logFile" 2>&1; then if ! systemctl start "${seafHub}" >> "$logFile" 2>&1; then
exitError 101 "Could not start ${seafHub}" exitError 101 "Could not start ${seafHub}"
else else
printf "${cyan}[%s] -- [INFO] Started service: %s --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Started service: %s --${norm}\n" \
"[$(stamp)]" "$seafHub" >> "$logFile" "$(stamp)" "$seafHub" >> "$logFile"
fi fi
elif [ "$1" = "stop" ]; then elif [ "$1" = "stop" ]; then
if ! systemctl stop "${seafHub}" >> "$logFile" 2>&1; then if ! systemctl stop "${seafHub}" >> "$logFile" 2>&1; then
exitError 103 "Could not stop ${seafHub}" exitError 103 "Could not stop ${seafHub}"
else else
printf "${cyan}[%s] -- [INFO] Stopped service: %s --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Stopped service: %s --${norm}\n" \
"[$(stamp)]" "$seafService" >> "$logFile" "$(stamp)" "$seafService" >> "$logFile"
fi fi
if ! systemctl stop "${seafService}" >> "$logFile" 2>&1; then if ! systemctl stop "${seafService}" >> "$logFile" 2>&1; then
exitError 102 "Could not stop ${seafService}" exitError 102 "Could not stop ${seafService}"
else else
printf "${cyan}[%s] -- [INFO] Stopped service: %s --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Stopped service: %s --${norm}\n" \
"[$(stamp)]" "$seafHub" >> "$logFile" "$(stamp)" "$seafHub" >> "$logFile"
fi fi
fi fi
} }
@@ -210,11 +209,11 @@ stamp () {
# same as exitError but for signal captures # same as exitError but for signal captures
trapExit () { trapExit () {
printf "${err}[%s] -- [ERROR] 99: Caught signal --${norm}\n" \ printf "${err}[%s] -- [ERROR] 99: Caught signal --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
cleanup cleanup
# note script completion with error # note script completion with error
printf "${err}[%s] --- %s execution was terminated via signal ---${norm}\n" \ printf "${err}[%s] --- %s execution was terminated via signal ---${norm}\n" \
"[$(stamp)]" "$scriptName" >> "$logFile" "$(stamp)" "$scriptName" >> "$logFile"
exit 99 exit 99
} }
@@ -230,7 +229,7 @@ scriptPath="$( CDPATH='' cd -- "$( dirname -- "$0" )" && pwd -P )"
scriptName="$( basename "$0" )" scriptName="$( basename "$0" )"
logFile="$scriptPath/${scriptName%.*}.log" logFile="$scriptPath/${scriptName%.*}.log"
warnCount=0 warnCount=0
configDetails="$scriptPath/seafbackup.details" configDetails="$scriptPath/${scriptName%.*}.details"
err503Copied=0 err503Copied=0
sqlCopied=0 sqlCopied=0
includeXtra=0 includeXtra=0
@@ -388,6 +387,11 @@ done
### check pre-requisites and default values ### check pre-requisites and default values
# check if running as root, otherwise exit
if [ $( id -u ) -ne 0 ]; then
printf "\n${err}ERROR: script MUST be run as ROOT${norm}\n\n"
exit 2
fi
# does the details file exist? # does the details file exist?
if [ ! -f "$configDetails" ]; then if [ ! -f "$configDetails" ]; then
badParam dne "(--details default)" "$configDetails" badParam dne "(--details default)" "$configDetails"
@@ -427,25 +431,25 @@ fi
### start logging ### start logging
printf "${magenta}[%s] --- Start %s execution ---${norm}\n" \ 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" \ printf "${cyan}[%s] -- [INFO] Log located at ${yellow}%s${cyan} --${norm}\n" \
"[$(stamp)]" "$logFile" >> "$logFile" "$(stamp)" "$logFile" >> "$logFile"
### 503 functionality ### 503 functionality
if [ "$use503" -eq 1 ]; then if [ "$use503" -eq 1 ]; then
printf "${cyan}[%s] -- [INFO] Copying 503 error page to " \ printf "${cyan}[%s] -- [INFO] Copying 503 error page to " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "webroot -- ${norm}\n" >> "$logFile" printf "webroot -- ${norm}\n" >> "$logFile"
if ! \cp --force "${err503Path}" "${webroot}/${err503File}" 2>> "$logFile" if ! \cp --force "${err503Path}" "${webroot}/${err503File}" 2>> "$logFile"
then then
printf "${warn}[%s] -- [WARNING] Failed to copy 503 error page. " \ printf "${warn}[%s] -- [WARNING] Failed to copy 503 error page. " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "Web users will NOT be notified --${norm}\n" >> "$logFile" printf "Web users will NOT be notified --${norm}\n" >> "$logFile"
warnCount=$((warnCount+1)) warnCount=$((warnCount+1))
else else
printf "${ok}[%s] -- [SUCCESS] 503 error page copied --${norm}\n" \ printf "${ok}[%s] -- [SUCCESS] 503 error page copied --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
# set cleanup flag # set cleanup flag
err503Copied=1 err503Copied=1
fi fi
@@ -455,7 +459,7 @@ fi
### stop seahub and seafile service if offline backup requested ### stop seahub and seafile service if offline backup requested
if [ "$offlineBackup" -eq 1 ]; then if [ "$offlineBackup" -eq 1 ]; then
printf "${cyan}[%s] -- [INFO] Stopping seafile services --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Stopping seafile services --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
seafSvc stop seafSvc stop
fi fi
@@ -473,7 +477,7 @@ case "${configDetails}" in
;; ;;
esac esac
printf "${cyan}[%s] -- [INFO] ${yellow}%s${cyan} imported --${norm}\n" \ printf "${cyan}[%s] -- [INFO] ${yellow}%s${cyan} imported --${norm}\n" \
"[$(stamp)]" "$configDetails" >> "$logFile" "$(stamp)" "$configDetails" >> "$logFile"
### dump sql databases ### dump sql databases
@@ -499,7 +503,7 @@ fi
## create tmp directory and generate dumpfile names ## create tmp directory and generate dumpfile names
printf "${cyan}[%s] -- [INFO] Dumping SQL databases --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Dumping SQL databases --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
# create temporary directory to dump files before borg backup # create temporary directory to dump files before borg backup
if ! sqlDumpDir=$( mktemp -d 2>>"$logFile" ); then if ! sqlDumpDir=$( mktemp -d 2>>"$logFile" ); then
exitError 111 "Could not create temporary directory to dump SQL files" exitError 111 "Could not create temporary directory to dump SQL files"
@@ -507,7 +511,7 @@ fi
# set cleanup flag # set cleanup flag
sqlCopied=1 sqlCopied=1
printf "${cyan}[%s] -- [INFO] SQL dump files will be temporarily stored in:" \ 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" printf "\n${yellow}%s/${cyan} --${norm}\n" "$sqlDumpDir" >> "$logFile"
# create unique names for database dump files # create unique names for database dump files
sqlDump_ccnet="backup-$(date +%Y%m%d_%H%M%S)_${ccnetDB_name}.sql" sqlDump_ccnet="backup-$(date +%Y%m%d_%H%M%S)_${ccnetDB_name}.sql"
@@ -532,18 +536,18 @@ if ! mysqldump -h"${sqlServer}" -u"${sqlUser}" -p"${sqlPass}" \
--opt "${seahubDB_name}" > "${sqlDumpDir}/${sqlDump_seahub}" 2>> "$logFile"; then --opt "${seahubDB_name}" > "${sqlDumpDir}/${sqlDump_seahub}" 2>> "$logFile"; then
exitError 117 "Could not dump ${seahubDB_name} database" exitError 117 "Could not dump ${seahubDB_name} database"
fi fi
printf "${ok}[%s] -- [SUCCESS] SQL databases dumped successfully --${norm}\n" \ printf "${ok}[%s] -- [SUCCESS] Dumped SQL databases --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
### pre-backup tasks completed -- move to borg tasks ### pre-backup tasks completed -- move to borg tasks
printf "${ok}[%s] -- [SUCCESS] Pre-backup tasks completed --${norm}\n" \ printf "${ok}[%s] -- [SUCCESS] Pre-backup tasks completed --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
### Run borg variable checks ### Run borg variable checks
printf "${cyan}[%s] -- [INFO] Verifying supplied borg details --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Verifying supplied borg details --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
## verify borg base directory ## verify borg base directory
if [ -z "${borgBaseDir}" ]; then if [ -z "${borgBaseDir}" ]; then
@@ -635,7 +639,7 @@ if [ ! -d "${borgBaseDir}/tmp" ]; then
exitError 132 "Unable to create borg ${borgBaseDir}/tmp directory" exitError 132 "Unable to create borg ${borgBaseDir}/tmp directory"
else else
printf "${cyan}[%s] -- [INFO] Created ${yellow}%s/tmp " \ printf "${cyan}[%s] -- [INFO] Created ${yellow}%s/tmp " \
"[$(stamp)]" "${borgBaseDir}" >> "$logFile" "$(stamp)" "${borgBaseDir}" >> "$logFile"
printf "${cyan}--${norm}\n" >> "$logFile" printf "${cyan}--${norm}\n" >> "$logFile"
fi fi
fi fi
@@ -668,18 +672,18 @@ fi
# execute borg # execute borg
printf "${cyan}[%s] -- [INFO] Executing borg backup operation --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Executing borg backup operation --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
${borgCMD} 2>> "$logFile" ${borgCMD} 2>> "$logFile"
borgResult="$?" borgResult="$?"
## check borg exit status ## check borg exit status
if [ "$borgResult" -eq 0 ]; then if [ "$borgResult" -eq 0 ]; then
printf "${ok}[%s] -- [SUCCESS] Borg backup completed " \ printf "${ok}[%s] -- [SUCCESS] Borg backup completed " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "successfully --${norm}\n" >> "$logFile" printf "successfully --${norm}\n" >> "$logFile"
elif [ "$borgResult" -eq 1 ]; then elif [ "$borgResult" -eq 1 ]; then
printf "${warn}[%s] -- [WARNING] Borg completed with warnings. " \ printf "${warn}[%s] -- [WARNING] Borg completed with warnings. " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "Review this logfile for details --${norm}\n" >> "$logFile" printf "Review this logfile for details --${norm}\n" >> "$logFile"
warnCount=$((warnCount+1)) warnCount=$((warnCount+1))
elif [ "$borgResult" -ge 2 ]; then elif [ "$borgResult" -ge 2 ]; then
@@ -688,7 +692,7 @@ elif [ "$borgResult" -ge 2 ]; then
exitError 138 "$err_1 $err_2" exitError 138 "$err_1 $err_2"
else else
printf "${warn}[%s] -- [WARNING] Borg exited with unknown return code. " \ printf "${warn}[%s] -- [WARNING] Borg exited with unknown return code. " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "Review this logfile for details --${norm}\n" >> "$logFile" printf "Review this logfile for details --${norm}\n" >> "$logFile"
warnCount=$((warnCount+1)) warnCount=$((warnCount+1))
fi fi
@@ -697,13 +701,13 @@ fi
### execute borg prune if paramters are provided, otherwise skip with a warning ### execute borg prune if paramters are provided, otherwise skip with a warning
if [ -n "${borgPruneSettings}" ]; then if [ -n "${borgPruneSettings}" ]; then
printf "${cyan}[%s] -- [INFO] Executing borg prune operation --${norm}\n" \ printf "${cyan}[%s] -- [INFO] Executing borg prune operation --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
borg prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \ borg prune --show-rc -v ${borgPruneParams} ${borgPruneSettings} \
2>> "$logFile" 2>> "$logFile"
borgPruneResult="$?" borgPruneResult="$?"
else else
printf "${warn}[%s] -- [WARNING] No prune parameters provided. " \ printf "${warn}[%s] -- [WARNING] No prune parameters provided. " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "Your archive will continue growing with each backup --${norm}\n" \ printf "Your archive will continue growing with each backup --${norm}\n" \
>> "$logFile" >> "$logFile"
warnCount=$((warnCount+1)) warnCount=$((warnCount+1))
@@ -713,10 +717,10 @@ fi
if [ -n "${borgPruneResult}" ]; then if [ -n "${borgPruneResult}" ]; then
if [ "${borgPruneResult}" -eq 0 ]; then if [ "${borgPruneResult}" -eq 0 ]; then
printf "${ok}[%s] -- [SUCCESS] Borg prune completed --${norm}\n" \ printf "${ok}[%s] -- [SUCCESS] Borg prune completed --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
elif [ "$borgPruneResult" -eq 1 ]; then elif [ "$borgPruneResult" -eq 1 ]; then
printf "${warn}[%s] -- [WARNING] Borg prune completed with warnings. " \ printf "${warn}[%s] -- [WARNING] Borg prune completed with warnings. " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "Review this logfile for details --${norm}\n" >> "$logFile" printf "Review this logfile for details --${norm}\n" >> "$logFile"
warnCount=$((warnCount+1)) warnCount=$((warnCount+1))
elif [ "$borgPruneResult" -ge 2 ]; then elif [ "$borgPruneResult" -ge 2 ]; then
@@ -725,7 +729,7 @@ if [ -n "${borgPruneResult}" ]; then
exitError 139 "$err_1 $err_2" exitError 139 "$err_1 $err_2"
else else
printf "${warn}[%s] -- [WARNING] Borg prune exited with an unknown " \ printf "${warn}[%s] -- [WARNING] Borg prune exited with an unknown " \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
printf "return code. Review this logfile for details --${norm}\n" \ printf "return code. Review this logfile for details --${norm}\n" \
>> "$logFile" >> "$logFile"
warnCount=$((warnCount+1)) warnCount=$((warnCount+1))
@@ -737,17 +741,16 @@ fi
# note successful completion of borg commands # note successful completion of borg commands
printf "${ok}[%s] -- [SUCCESS] Backup operations completed --${norm}\n" \ printf "${ok}[%s] -- [SUCCESS] Backup operations completed --${norm}\n" \
"[$(stamp)]" >> "$logFile" "$(stamp)" >> "$logFile"
# cleanup # cleanup
cleanup cleanup
# note complete success, tally warnings and exit # note complete success, tally warnings and exit
printf "${ok}[%s] -- [SUCCESS] All processes completed successfully --" \ printf "${ok}[%s] -- [SUCCESS] All processes completed --${norm}\n" \
"${norm}\n" \ "$(stamp)" >> "$logFile"
"[$(stamp)]" >> "$logFile"
printf "${magenta}[%s] --- %s execution completed ---${norm}\n" \ printf "${magenta}[%s] --- %s execution completed ---${norm}\n" \
"[$(stamp)]" "$scriptName" >> "$logFile" "$(stamp)" "$scriptName" >> "$logFile"
if [ "$warnCount" -gt 0 ]; then if [ "$warnCount" -gt 0 ]; then
printf "${warn}%s warnings issued!${norm}\n" "${warnCount}" >> "$logFile" printf "${warn}%s warnings issued!${norm}\n" "${warnCount}" >> "$logFile"
else else