2018-09-04 18:03:37 -06:00
|
|
|
#!/bin/bash
|
2018-09-04 18:13:18 -06:00
|
|
|
|
|
|
|
#######
|
|
|
|
### Backup NextCloud13 installation to external repo using Borg Backup
|
2018-09-06 00:02:39 -06:00
|
|
|
### Assuming both NextCloud & Borg setup as outlined in their respecitive
|
2018-09-04 18:13:18 -06:00
|
|
|
### series at https://mytechiethoughts.com
|
|
|
|
###
|
|
|
|
### Events:
|
|
|
|
### 1. Copy 503 error page to stop NGINX from serving web clients.
|
|
|
|
### (this depends on a complementary NGINX configuration)
|
2018-09-04 20:20:10 -06:00
|
|
|
### 2. Put NextCloud in maintenance mode to prevent logins and changes.
|
2018-09-04 18:13:18 -06:00
|
|
|
### 3. SQLdump from NextCloud.
|
|
|
|
### 4. Borg backup all files from xtraLocations.
|
|
|
|
### 5. Borg backup NextCloud data and files.
|
|
|
|
### 6. Put NextCloud back into operating mode.
|
|
|
|
### 7. Delete 503 error page so NGINX can serve web clients again.
|
2018-09-06 00:02:39 -06:00
|
|
|
###
|
|
|
|
### Usage: ./borgbackup [verbose:normal(default):quiet]
|
|
|
|
### Options:
|
|
|
|
### verbose - All logging turned on, including a list of each file being
|
|
|
|
### backed up/skipped/etc. (This can lead to very large logs)
|
|
|
|
### normal - This is the default setting. If nothing is specified, this
|
|
|
|
### setting will be used. Errors, warnings & summary of borgbackup will
|
|
|
|
### be logged.
|
|
|
|
### quiet - Minimal logging. Errors and warnings only and confirmation of
|
|
|
|
### of backup success.
|
2018-09-04 18:13:18 -06:00
|
|
|
#######
|
|
|
|
|
|
|
|
|
|
|
|
### Script variables -- please ensure they are accurate!
|
|
|
|
|
2018-09-04 20:20:10 -06:00
|
|
|
# web user on your system (default: www-data)
|
|
|
|
webUser=www-data
|
|
|
|
|
2018-09-04 18:13:18 -06:00
|
|
|
# FULL path to NGINX webroot (default: /usr/share/nginx/html)
|
|
|
|
webroot=/usr/share/nginx/html
|
|
|
|
|
|
|
|
# FULL path to NextCloud root directory
|
2018-09-06 00:02:39 -06:00
|
|
|
# By default, this is a folder within your webroot. If your setup is different
|
|
|
|
# then provide the FULL path here. (default: webroot/nextcloud)
|
2018-09-04 18:13:18 -06:00
|
|
|
ncroot="$webroot/nextcloud"
|
|
|
|
|
2018-09-04 22:12:20 -06:00
|
|
|
# NextCloud data directory
|
|
|
|
# If this is setup according to the blog series at https://mytechiethoughts.com
|
|
|
|
# then this is '/var/nc_data'. If not, please change as appropriate for your
|
2018-09-06 00:02:39 -06:00
|
|
|
# environment. (default: /var/nc_data)
|
2018-09-04 22:12:20 -06:00
|
|
|
ncdata=/var/nc_data
|
|
|
|
|
2018-09-04 18:13:18 -06:00
|
|
|
# name of 503-error page (default: 503-error.html)
|
|
|
|
# MUST be in the same directory as THIS script
|
|
|
|
err503FileName=503-backup.html
|
|
|
|
|
|
|
|
# desired directory for SQLdump -- will be created if necessary
|
|
|
|
# (default: /SQLdump)
|
2018-09-06 01:58:31 -06:00
|
|
|
sqlDumpDir=/SQLdump
|
2018-09-04 18:13:18 -06:00
|
|
|
|
2018-09-04 18:28:40 -06:00
|
|
|
# FULL path to SQL details file (explained in blog)
|
|
|
|
# This is a 4 line file in the EXACT format:
|
2018-09-06 00:02:39 -06:00
|
|
|
#sqlServerHostName
|
2018-09-04 18:28:40 -06:00
|
|
|
#sqlDBUsername
|
|
|
|
#sqlDBPassword
|
|
|
|
#sqlDBName
|
|
|
|
#(default: /root/sqlDetails)
|
|
|
|
sqlDetails=/root/sqlDetails
|
|
|
|
|
2018-09-04 18:13:18 -06:00
|
|
|
# Borg BASE directory (default: /var/borgbackup)
|
|
|
|
borgBaseDir=/var/borgbackup
|
|
|
|
|
|
|
|
# FULL path to your remote server SSH private keyfile (no default)
|
|
|
|
borgRemoteSSHKeyfile=/var/borgbackup/rsync.key
|
|
|
|
|
|
|
|
# Borg remote path (default for rsync: borg1)
|
|
|
|
borgRemotePath=borg1
|
|
|
|
|
2018-09-05 17:48:12 -06:00
|
|
|
# Borg 'checkpoint' interval in seconds
|
|
|
|
# This determines when snapshots are taken so that interrupted backups
|
|
|
|
# can be restored from that point in time
|
|
|
|
# (default: 300 seconds = 5 minutes)
|
|
|
|
borgCheckpoint=300
|
|
|
|
|
2018-09-04 18:13:18 -06:00
|
|
|
# FULL path to Borg repo details file (explained in blog)
|
|
|
|
# This is a 2 line file in the EXACT format:
|
|
|
|
# repo-name in format user@server.tld:repo
|
|
|
|
# passphrase
|
|
|
|
# (default: borgBaseDir/repoDetails.borg)
|
|
|
|
borgDetails="$borgBaseDir/repoDetails.borg"
|
|
|
|
|
|
|
|
# FULL path to the extra source-list file (explained in blog)
|
|
|
|
# This file lists any extra files and directories that should be included
|
2018-09-06 00:02:39 -06:00
|
|
|
# in the backup in addition to NextCloud program and data files.
|
2018-09-04 18:13:18 -06:00
|
|
|
# One source-entry per line.
|
|
|
|
# No spaces, comments or any other extraneous information, just the files/dirs
|
2018-09-06 00:02:39 -06:00
|
|
|
# Directories must end with tailing slash (i.e. directory/name/)
|
2018-09-04 18:13:18 -06:00
|
|
|
# (default: borgBaseDir/xtraLocations.borg)
|
|
|
|
borgXtraFiles="$borgBaseDir/xtraLocations.borg"
|
|
|
|
|
2018-09-05 17:20:08 -06:00
|
|
|
# FULL path to the exclude source-list (explained in blog)
|
|
|
|
# This file lists any files and directories that should be excluded from
|
|
|
|
# the backup.
|
|
|
|
# MUST conform to borg patterns -- 'borg help patterns' for more information
|
|
|
|
# (default: borgBaseDir/excludeLocations.borg)
|
|
|
|
borgExcludeFiles="$borgBaseDir/excludeLocations.borg"
|
|
|
|
|
2018-09-04 18:13:18 -06:00
|
|
|
# Pruning options for borg archive (see BorgBackup documentation for details)
|
|
|
|
# This default example keeps all backups within the last 14 days, 12 weeks
|
|
|
|
# of end-of-week backups and 6 months of end-of-month backups.
|
|
|
|
borgPrune='--keep-within=14d --keep-weekly=12 --keep-monthly=6'
|
|
|
|
|
2018-09-06 00:02:39 -06:00
|
|
|
# desired name and location of log file for this script (will be created)
|
|
|
|
# NOTE: This file can get quite large, ensure logrotate is setup!
|
2018-09-04 18:13:18 -06:00
|
|
|
# (default: /var/log/mailcow_backup.log)
|
|
|
|
logFile=/var/log/borgbackup.log
|
|
|
|
|
|
|
|
|
|
|
|
### Do NOT edit below this line
|
|
|
|
|
2018-09-04 18:14:26 -06:00
|
|
|
|
|
|
|
## Ensure script is running as root (required) otherwise, exit
|
2018-09-05 17:20:38 -06:00
|
|
|
if [ $(id -u) -ne 0 ]; then
|
|
|
|
echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`] This script MUST" \
|
|
|
|
"be run as ROOT."
|
|
|
|
echo -e "\e[4;31mScript aborted\e[0;31m.\e[0m"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-09-04 18:14:26 -06:00
|
|
|
|
|
|
|
|
2018-09-06 00:37:21 -06:00
|
|
|
## elevate script -- used during program testing
|
2018-09-05 17:20:38 -06:00
|
|
|
#if [ $EUID != 0 ]; then
|
2018-09-06 00:03:40 -06:00
|
|
|
# sudo "$0" "$@"
|
2018-09-05 17:20:38 -06:00
|
|
|
# exit $?
|
|
|
|
#fi
|
2018-09-04 18:14:26 -06:00
|
|
|
|
|
|
|
|
2018-09-06 00:37:21 -06:00
|
|
|
### Functions:
|
|
|
|
|
|
|
|
function quit {
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
# exit gracefully
|
|
|
|
echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \
|
|
|
|
"--Backup operations completed SUCCESSFULLY--\e[0m" >> $logFile
|
|
|
|
exit 0
|
|
|
|
elif [ "$2" = "warn" ]; then
|
|
|
|
# exit with warning code
|
|
|
|
echo -e "\e[1;33m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \
|
2018-09-07 02:23:02 -06:00
|
|
|
"--Script exiting with WARNING(S) (code: ${exitWarning[*]})--\e[0m" >> $logFile
|
2018-09-06 00:37:21 -06:00
|
|
|
exit "$1"
|
|
|
|
else
|
|
|
|
# exit with error code
|
|
|
|
echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \
|
|
|
|
"--Script exiting with ERROR (code: $1)--\e[0m" >> $logFile
|
|
|
|
exit "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-09-06 01:16:48 -06:00
|
|
|
function checkExist {
|
|
|
|
if [ "$1" = "find" ]; then
|
|
|
|
if [ -e "$3" ]; then
|
2018-09-06 02:07:21 -06:00
|
|
|
echo -e "\e[0m[`date +%Y-%m-%d` `date +%H:%M:%S`] Found:" \
|
|
|
|
"\e[0;33m${3}\e[0m" >> $logFileVerbose
|
2018-09-06 01:16:48 -06:00
|
|
|
return 0
|
|
|
|
elif [ "$2" = "createDir" ]; then
|
2018-09-06 02:07:21 -06:00
|
|
|
echo -e "\e[1;36m[`date +%Y-%m-%d` `date +%H:%M:%S`] Creating:" \
|
|
|
|
"${3}...\e[0m" | tee -a $logFileVerbose $logFileNormal > \
|
|
|
|
/dev/null
|
2018-09-06 01:56:28 -06:00
|
|
|
mkdir -p "$3" 2>&1 | tee -a $logFileVerbose $logFileNormal \
|
|
|
|
> /dev/null
|
2018-09-06 01:44:18 -06:00
|
|
|
echo -e "\e[0;36m...done\e[0m" | tee -a $logFileVerbose \
|
|
|
|
$logFileNormal > /dev/null
|
2018-09-06 01:16:48 -06:00
|
|
|
return 1
|
|
|
|
elif [ "$2" = "warn" ]; then
|
2018-09-06 02:59:22 -06:00
|
|
|
echo -e "\e[1;33m[`date +%Y-%m-%d` `date +%H:%M:%S`] --WARNING:" \
|
|
|
|
"${3} was not found--\e[0m" >> $logFile
|
2018-09-06 04:00:11 -06:00
|
|
|
exitWarning+=('101')
|
2018-09-06 01:16:48 -06:00
|
|
|
return 2
|
|
|
|
elif [ "$2" = "error" ]; then
|
2018-09-06 02:59:22 -06:00
|
|
|
echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`] --ERROR:" \
|
|
|
|
"${3} was not found--\e[0m" >> $logFile
|
2018-09-06 01:16:48 -06:00
|
|
|
quit 101
|
2018-09-07 01:53:17 -06:00
|
|
|
else
|
|
|
|
# file not found, return proper code
|
|
|
|
return 3
|
2018-09-06 01:16:48 -06:00
|
|
|
fi
|
|
|
|
elif [ "$1" = "verify" ]; then
|
2018-09-06 01:28:09 -06:00
|
|
|
if [ -e "$2" ]; then
|
2018-09-06 02:10:55 -06:00
|
|
|
echo -e "\e[0m[`date +%Y-%m-%d` `date +%H:%M:%S`] Confirmed:" \
|
2018-09-06 02:07:21 -06:00
|
|
|
"\e[0;33m${2}\e[0m" >> $logFileVerbose
|
2018-09-06 01:16:48 -06:00
|
|
|
return 0
|
|
|
|
else
|
2018-09-06 02:59:22 -06:00
|
|
|
echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`] --ERROR:" \
|
|
|
|
"Problem creating ${2}--\e[0m" >> $logFile
|
2018-09-06 01:16:48 -06:00
|
|
|
quit 102
|
|
|
|
fi
|
2018-09-07 01:23:33 -06:00
|
|
|
else
|
|
|
|
return 105
|
2018-09-06 01:16:48 -06:00
|
|
|
fi
|
|
|
|
}
|
2018-09-06 00:37:21 -06:00
|
|
|
### End of functions
|
|
|
|
|
|
|
|
|
2018-09-04 18:15:48 -06:00
|
|
|
## Write script execution start in log file
|
|
|
|
echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \
|
|
|
|
"--Begin backup operations--\e[0m" >> $logFile
|
|
|
|
|
2018-09-04 18:20:38 -06:00
|
|
|
## Parse supplied variables and determine additional script vars
|
|
|
|
scriptPath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
err503FullPath="$scriptPath/$err503FileName"
|
2018-09-06 04:00:11 -06:00
|
|
|
exitWarning=()
|
2018-09-04 18:20:38 -06:00
|
|
|
|
2018-09-06 00:26:33 -06:00
|
|
|
## Determine verbosity level for logging
|
|
|
|
if [ "$1" = "verbose" ]; then
|
|
|
|
borgCreateParams='--list --stats'
|
|
|
|
borgPruneParams='--list'
|
|
|
|
logFileVerbose="$logFile"
|
|
|
|
unset logFileNormal
|
|
|
|
unset logFileQuiet
|
|
|
|
elif [ "$1" = "normal" ] || [ -z "$1" ]; then
|
|
|
|
borgCreateParams='--stats'
|
|
|
|
borgPruneParams='--list'
|
|
|
|
unset logFileVerbose
|
|
|
|
logFileNormal="$logFile"
|
|
|
|
unset logFileQuiet
|
|
|
|
elif [ "$1" = "quiet" ]; then
|
|
|
|
unset borgCreateParams
|
|
|
|
unset borgPruneParams
|
|
|
|
unset logFileVerbose
|
|
|
|
unset logFileNormal
|
|
|
|
else
|
|
|
|
quit 2
|
|
|
|
fi
|
|
|
|
|
2018-09-04 18:20:38 -06:00
|
|
|
## Export logfle location for use by external programs
|
|
|
|
export logFile="$logFile"
|
|
|
|
|
2018-09-04 18:22:46 -06:00
|
|
|
## Check for sqlDumpDir and create if necessary
|
2018-09-06 01:28:09 -06:00
|
|
|
checkExist find createDir $sqlDumpDir
|
|
|
|
checkResult="$?"
|
|
|
|
if [ "$checkResult" = "1" ]; then
|
|
|
|
# verify creation successful
|
|
|
|
checkExist verify $sqlDumpDir
|
|
|
|
fi
|
|
|
|
|
2018-09-04 18:22:46 -06:00
|
|
|
## Create unique filename for sqlDump file
|
2018-09-06 02:01:53 -06:00
|
|
|
sqlDumpFile="backup_`date +%Y%m%d_%H%M%S`.sql"
|
2018-09-04 18:22:46 -06:00
|
|
|
echo -e "\e[0m[`date +%Y-%m-%d` `date +%H:%M:%S`] mysql dump file will be" \
|
|
|
|
"stored at:" >> $logFile
|
2018-09-06 02:01:53 -06:00
|
|
|
echo -e "\e[0;33m$sqlDumpDir/$sqlDumpFile\e[0m" | tee -a $logFileVerbose \
|
|
|
|
$logFileNormal > /dev/null
|
2018-09-04 18:22:46 -06:00
|
|
|
|
2018-09-04 18:30:38 -06:00
|
|
|
## Find 503 error page and copy to NGINX webroot
|
|
|
|
## File must be in the same location as this script
|
|
|
|
## IF file is not found, log warning but continue script
|
2018-09-06 02:37:41 -06:00
|
|
|
checkExist find warn $err503FullPath
|
|
|
|
checkResult="$?"
|
|
|
|
if [ "$checkResult" = "2" ]; then
|
|
|
|
# file not found, issue warning
|
2018-09-06 02:58:26 -06:00
|
|
|
echo -e "\e[1;33m--WARNING: The 503 file should be re-created" \
|
|
|
|
"ASAP.--" >> $logFile
|
|
|
|
echo -e "\e[1;33m--WARNING: Web users will NOT be notified the" \
|
|
|
|
"server is down.--\e[0m" >> $logFile
|
2018-09-06 02:37:41 -06:00
|
|
|
echo -e "Script will continue processing..." >> $logFile
|
|
|
|
else
|
|
|
|
# file found, copy it to webroot
|
|
|
|
echo -e "\e[1;36m[`date +%Y-%m-%d` `date +%H:%M:%S`] Copying 503 error" \
|
2018-09-06 02:58:26 -06:00
|
|
|
"page to NGINX webroot...\e[0m" | tee -a $logFileVerbose \
|
|
|
|
$logFileNormal > /dev/null
|
2018-09-06 02:48:16 -06:00
|
|
|
cp $err503FullPath $webroot/ 2>&1 | tee -a $logFileVerbose $logFileNormal \
|
|
|
|
> /dev/null
|
|
|
|
echo -e "\e[0;36m...done\e[0m" | tee -a $logFileVerbose $logFileNormal \
|
2018-09-06 02:37:41 -06:00
|
|
|
> /dev/null
|
|
|
|
# verify copy was successful
|
|
|
|
checkExist find warn "$webroot/$err503FileName"
|
|
|
|
checkResult="$?"
|
|
|
|
if [ "$checkResult" = "2" ]; then
|
|
|
|
# file not found, issue warning
|
2018-09-06 02:58:26 -06:00
|
|
|
echo -e "\e[1;33m[`date +%Y-%m-%d` `date +%H:%M:%S`] --WARNING: " \
|
2018-09-06 02:37:41 -06:00
|
|
|
"There was a problem copying the 503 error page to" \
|
2018-09-06 02:58:26 -06:00
|
|
|
"webroot.--\e[0m" >> $logFile
|
|
|
|
echo -e "\e[1;33m--WARNING: Web users will NOT be notified the" \
|
|
|
|
"server is down.--\e[0m" >> $logFile
|
2018-09-06 02:37:41 -06:00
|
|
|
echo -e "Script will continue processing..." >> $logFile
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-09-04 20:20:10 -06:00
|
|
|
## Put NextCloud in maintenance mode
|
2018-09-04 20:28:52 -06:00
|
|
|
echo -e "\e[1;36m[`date +%Y-%m-%d` `date +%H:%M:%S`] Putting NextCloud" \
|
2018-09-06 03:20:09 -06:00
|
|
|
"in maintenance mode...\e[0m" >> $logFile
|
2018-09-05 17:22:57 -06:00
|
|
|
sudo -u ${webUser} php ${ncroot}/occ maintenance:mode --on >> $logFile 2>&1
|
2018-09-04 20:28:52 -06:00
|
|
|
# verify
|
2018-09-06 03:11:13 -06:00
|
|
|
maintResult="$?"
|
2018-09-06 03:20:09 -06:00
|
|
|
|
|
|
|
if [ "$maintResult" = "0" ]; then
|
2018-09-04 20:28:52 -06:00
|
|
|
echo -e "\e[0;36m...done\e[0m" >> $logFile
|
|
|
|
else
|
2018-09-06 03:14:34 -06:00
|
|
|
quit 500
|
2018-09-04 20:28:52 -06:00
|
|
|
fi
|
|
|
|
|
2018-09-04 18:34:14 -06:00
|
|
|
## Read sqlDetails file and extract necessary information
|
|
|
|
mapfile -t sqlParams < $sqlDetails
|
|
|
|
|
2018-09-04 20:20:10 -06:00
|
|
|
## Dump SQL
|
2018-09-04 20:32:29 -06:00
|
|
|
echo -e "\e[1;36m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \
|
2018-09-06 03:14:19 -06:00
|
|
|
"Dumping SQL...\e[0m" >> $logFileVerbose
|
2018-09-04 22:27:13 -06:00
|
|
|
mysqldump --single-transaction -h${sqlParams[0]} -u${sqlParams[1]} \
|
2018-09-06 03:14:19 -06:00
|
|
|
-p${sqlParams[2]} ${sqlParams[3]} > "$sqlDumpDir/$sqlDumpFile" \
|
|
|
|
2>> $logFileVerbose
|
|
|
|
dumpResult="$?"
|
2018-09-04 20:32:29 -06:00
|
|
|
# verify
|
2018-09-06 03:14:19 -06:00
|
|
|
if [ "$dumpResult" = "0" ]; then
|
|
|
|
echo -e "\e[0;36m...done\e[0m" >> $logFileVerbose
|
2018-09-04 20:32:29 -06:00
|
|
|
else
|
2018-09-06 03:14:19 -06:00
|
|
|
quit 200
|
2018-09-04 20:32:29 -06:00
|
|
|
fi
|
2018-09-04 20:34:32 -06:00
|
|
|
|
2018-09-04 20:38:09 -06:00
|
|
|
## Ready for Borg
|
|
|
|
echo -e "\e[1;39m[`date +%Y-%m-%d` `date +%H:%M:%S`] Pre-backup tasks" \
|
|
|
|
"completed... calling BorgBackup" >> $logFile
|
|
|
|
|
|
|
|
## Generate and export variables required for BorgBackup
|
|
|
|
export BORG_BASE_DIR="$borgBaseDir"
|
|
|
|
export BORG_REMOTE_PATH="$borgRemotePath"
|
|
|
|
export BORG_RSH="ssh -i $borgRemoteSSHKeyfile"
|
|
|
|
export BORG_REPO="$(head -1 $borgDetails)"
|
|
|
|
export BORG_PASSPHRASE="$(tail -1 $borgDetails)"
|
|
|
|
|
2018-09-04 22:12:20 -06:00
|
|
|
## Process borgXtraFiles into array variable
|
|
|
|
mapfile -t xtraFiles < $borgXtraFiles
|
|
|
|
|
|
|
|
## Call BorgBackup
|
2018-09-06 03:30:43 -06:00
|
|
|
borg --show-rc create ${borgCreateParams} --exclude-from $borgExcludeFiles \
|
2018-09-05 17:48:12 -06:00
|
|
|
--checkpoint-interval $borgCheckpoint ::`date +%Y-%m-%d_%H%M%S` \
|
2018-09-04 22:12:20 -06:00
|
|
|
"${xtraFiles[@]}" \
|
|
|
|
"$ncdata" \
|
2018-09-06 03:30:43 -06:00
|
|
|
"$sqlDumpDir/$sqlDumpFile" >> $logFile 2>&1
|
|
|
|
|
|
|
|
borgCreateResult=$(echo "$?")
|
2018-09-04 22:12:20 -06:00
|
|
|
|
2018-09-04 22:12:49 -06:00
|
|
|
# Report BorgBackup exit status
|
2018-09-06 03:30:43 -06:00
|
|
|
if [ "$borgCreateResult" = "0" ]; then
|
|
|
|
echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`] --SUCCESS--" \
|
2018-09-04 22:12:49 -06:00
|
|
|
"BorgBackup completed successfully.\e[0m" >> $logFile
|
2018-09-06 03:30:43 -06:00
|
|
|
elif [ "$borgCreateResult" = "1" ]; then
|
|
|
|
echo -e "\e[1;33m[`date +%Y-%m-%d` `date +%H:%M:%S`] --WARNING--" \
|
2018-09-04 22:12:49 -06:00
|
|
|
"BorgBackup completed with WARNINGS." >> $logFile
|
2018-09-06 03:41:16 -06:00
|
|
|
echo -e "--WARNING-- Please check Borg's output.\e[0m" >> $logFile
|
2018-09-04 22:12:49 -06:00
|
|
|
else
|
2018-09-06 03:30:43 -06:00
|
|
|
echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`] --ERROR--" \
|
2018-09-04 22:12:49 -06:00
|
|
|
"BorgBackup encountered a serious ERROR." >> $logFile
|
2018-09-06 03:41:16 -06:00
|
|
|
echo -e "--ERROR-- Please check Borg's output.\e[0m" >> $logFile
|
2018-09-04 22:12:49 -06:00
|
|
|
fi
|
2018-09-04 22:12:20 -06:00
|
|
|
|
2018-09-04 22:13:26 -06:00
|
|
|
## Have BorgBackup prune the repo to remove old archives
|
2018-09-06 03:30:43 -06:00
|
|
|
borg --show-rc prune -v ${borgPruneParams} ${borgPrune} :: >> $logFile 2>&1
|
|
|
|
|
|
|
|
borgPruneResult=$(echo "$?")
|
2018-09-04 22:13:26 -06:00
|
|
|
|
|
|
|
# Report BorgBackup exit status
|
2018-09-06 03:30:43 -06:00
|
|
|
if [ "$borgPruneResult" = "0" ]; then
|
|
|
|
echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`] --SUCCESS--" \
|
2018-09-04 22:13:26 -06:00
|
|
|
"BorgBackup PRUNE operation completed successfully.\e[0m" >> $logFile
|
2018-09-06 03:30:43 -06:00
|
|
|
elif [ "$borgPruneResult" = "1" ]; then
|
|
|
|
echo -e "\e[1;33m[`date +%Y-%m-%d` `date +%H:%M:%S`] --WARNING--" \
|
2018-09-04 22:13:26 -06:00
|
|
|
"BorgBackup PRUNE operation completed with WARNINGS." >> $logFile
|
2018-09-06 03:41:16 -06:00
|
|
|
echo -e "--WARNING-- Please check Borg's output.\e[0m" >> $logFile
|
2018-09-04 22:13:26 -06:00
|
|
|
else
|
2018-09-06 03:30:43 -06:00
|
|
|
echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`] --ERROR--" \
|
2018-09-04 22:13:26 -06:00
|
|
|
"BorgBackup PRUNE operation encountered a serious ERROR." >> $logFile
|
2018-09-06 03:41:16 -06:00
|
|
|
echo -e "--ERROR-- Please check Borg's output.\e[0m" >> $logFile
|
2018-09-04 22:13:26 -06:00
|
|
|
fi
|
2018-09-04 22:12:20 -06:00
|
|
|
|
2018-09-07 01:23:33 -06:00
|
|
|
|
2018-09-04 22:18:06 -06:00
|
|
|
## Put NextCloud back into operational mode
|
2018-09-04 22:32:42 -06:00
|
|
|
echo -e "\e[1;36m[`date +%Y-%m-%d` `date +%H:%M:%S`] Taking NextCloud" \
|
2018-09-06 04:02:21 -06:00
|
|
|
"out of maintenance mode...\e[0m" >> $logFile
|
2018-09-05 17:22:57 -06:00
|
|
|
sudo -u ${webUser} php ${ncroot}/occ maintenance:mode --off >> $logFile 2>&1
|
2018-09-06 04:02:21 -06:00
|
|
|
|
|
|
|
maintResult="$?"
|
|
|
|
|
|
|
|
# verify but continue if problems since we need to cleanup before exiting
|
|
|
|
if [ "$maintResult" = "0" ]; then
|
2018-09-04 22:18:06 -06:00
|
|
|
echo -e "\e[0;36m...done\e[0m" >> $logFile
|
|
|
|
else
|
2018-09-06 04:00:11 -06:00
|
|
|
echo -e "\e[1;31m--WARNING-- There was a problem taking NextCloud" \
|
|
|
|
"out of maintenance mode. This MUST be done manually before" \
|
|
|
|
"NextCloud can be used." >> $logFile
|
|
|
|
exitWarning+=('501')
|
2018-09-04 22:18:06 -06:00
|
|
|
fi
|
|
|
|
|
2018-09-04 22:15:00 -06:00
|
|
|
## Remove 503 error page from webroot so NGINX serves web clients again
|
|
|
|
echo -e "\e[1;36m[`date +%Y-%m-%d` `date +%H:%M:%S`] Removing 503 error page" \
|
2018-09-06 04:19:11 -06:00
|
|
|
"from webroot...\e[0m" | tee -a $logFileVerbose $logFileNormal > /dev/null
|
|
|
|
rm -f "$webroot/$err503FileName" 2>&1 | tee -a $logFileVerbose $logFileNormal \
|
|
|
|
> /dev/null
|
2018-09-04 22:15:00 -06:00
|
|
|
# verify actually removed
|
2018-09-07 02:32:51 -06:00
|
|
|
checkExist find null "$webroot/$err503FileName"
|
2018-09-06 04:19:11 -06:00
|
|
|
checkResult="$?"
|
2018-09-07 01:57:14 -06:00
|
|
|
if [ "$checkResult" = "3" ]; then
|
|
|
|
echo -e "\e[0;36m...done\e[0m" | tee -a $logFileVerbose $logFileNormal \
|
|
|
|
> /dev/null
|
|
|
|
else
|
2018-09-06 04:19:11 -06:00
|
|
|
echo -e "\e[1;33m[`date +%Y-%m-%d` `date +%H:%M:%S`] --WARNING:" \
|
|
|
|
"Problem encountered removing 503 error page from webroot." \
|
2018-09-06 04:20:17 -06:00
|
|
|
"Manually remove this file or NGINX will not serve web" \
|
2018-09-06 04:19:11 -06:00
|
|
|
"clients.--" >> $logFile
|
2018-09-06 04:28:11 -06:00
|
|
|
echo -e "Script will continue processing..." >> $logFileVerbose
|
2018-09-06 04:19:11 -06:00
|
|
|
exitWarning+=('103')
|
2018-09-04 22:15:00 -06:00
|
|
|
fi
|
|
|
|
|
2018-09-04 22:20:33 -06:00
|
|
|
## Remove sqlDump file
|
|
|
|
echo -e "\e[1;36m[`date +%Y-%m-%d` `date +%H:%M:%S`] Removing sqlDump" \
|
2018-09-06 04:28:11 -06:00
|
|
|
"file...\e[0m" >> $logFileVerbose
|
|
|
|
rm -f "$sqlDumpDir/$sqlDumpFile" >> $logFile 2>&1
|
2018-09-04 22:20:33 -06:00
|
|
|
# verify actually removed
|
2018-09-07 02:32:51 -06:00
|
|
|
checkExist find null "$sqlDumpDir/$sqlDumpFile"
|
2018-09-06 04:28:11 -06:00
|
|
|
checkResult="$?"
|
2018-09-07 02:00:00 -06:00
|
|
|
if [ "$checkResult" = "3" ]; then
|
|
|
|
echo -e "\e[0;36m...done\e[0m" >> $logFileVerbose
|
|
|
|
else
|
2018-09-06 04:28:11 -06:00
|
|
|
echo -e "\e[1;33m[`date +%Y-%m-%d` `date +%H:%M:%S`] --WARNING:" \
|
|
|
|
"Error removing sqldump file. Please remove manually.\e[0m--" >> $logFileVerbose
|
|
|
|
echo -e "Script will continue processing..." >> $logFileVerbose
|
2018-09-07 02:00:00 -06:00
|
|
|
exitWarning+=('103')
|
2018-09-04 22:20:33 -06:00
|
|
|
fi
|
2018-09-04 22:15:00 -06:00
|
|
|
|
2018-09-06 04:28:11 -06:00
|
|
|
|
2018-09-04 22:20:52 -06:00
|
|
|
## Log completion of script
|
2018-09-07 02:23:02 -06:00
|
|
|
if [ ${#exitWarning[@]} -gt 0 ]; then
|
|
|
|
quit 100 warn
|
|
|
|
else
|
|
|
|
quit
|
|
|
|
fi
|
2018-09-04 22:15:00 -06:00
|
|
|
|
2018-09-07 02:23:02 -06:00
|
|
|
# end of script -- this exit should not be necessary
|
|
|
|
exit 999
|