seafileBackup/backup_new.sh

93 lines
2.0 KiB
Bash
Raw Normal View History

2019-05-21 17:27:10 -06:00
#!/bin/sh
#######
### Backup Seafile/Seafile Pro server on bare-metal (NOT DOCKER)
#######
### text formatting presents
norm="\e[0m"
bold="\e[1m"
err="\e[1;31m"
warn="\e[1;93m"
ok="\e[32m"
yellow="\e[93m"
cyan="\e[96m"
mag="\e[95m"
### functions
2019-05-22 22:58:07 -06:00
# control seafile services (systemd)
seafSvc () {
if [ "$1" = "start" ]; then
if ! systemctl start "${seafSvc}" >> "$logFile" 2>&1; then
echo "error starting seafile service"
exit 100
fi
if ! systemctl start "${seafHub}" >> "$logFile" 2>&1; then
echo "error starting seahub service"
exit 101
fi
elif [ "$1" = "stop" ]; then
if ! systemctl stop "${seafHub}" >> "$logFile" 2>&1; then
echo "error stopping seahub service"
exit 103
fi
if ! systemctl stop "${seafSvc}" >> "$logFile" 2>&1; then
echo "error stopping seafile service"
exit 102
fi
fi
}
2019-05-21 17:27:10 -06:00
# generate dynamic timestamps
stamp () {
(date +%F" "%T)
}
### end of functions
### default variable values
2019-05-23 20:57:05 -06:00
## script related
2019-05-21 17:27:10 -06:00
# store logfile in the same directory as this script file using the same file
# name as the script but with the extension '.log'
scriptPath="$( CDPATH= cd -- "$( dirname -- "$0" )" && pwd -P )"
scriptName="$( basename "$0" )"
logFile="$scriptPath/${scriptName%.*}.log"
2019-05-23 20:57:05 -06:00
# borg output verbosity -- normal
borgCreateParams='--stats'
borgPruneParams='--list'
detailsFile="$scriptPath/seafbackup.details"
2019-05-21 17:27:10 -06:00
2019-05-23 20:57:05 -06:00
# 503 related
err503Path="$scriptPath/503_backup.html"
err503File="${err503Path##*/}"
webroot="/usr/share/nginx/html"
# seafile related
2019-05-22 22:58:07 -06:00
offlineBackup=0
seafSvc="seafile.service"
seafHub="seahub.service"
2019-05-23 20:57:05 -06:00
seafUser="seafile"
2019-05-22 22:58:07 -06:00
seafDir="/opt/seafile"
2019-05-23 20:57:05 -06:00
seafData="/var/seafile"
2019-05-21 17:27:10 -06:00
### start logging
printf "${mag}[%s] --- Start %s execution ---${norm}\n" \
"$(stamp)" "$scriptName" >> "$logFile"
printf "${cyan}[%s] -- [INFO] Log located at ${yellow}%s${cyan} --${norm}\n" \
"$(stamp)" "$logFile" >> "$logFile"
2019-05-22 22:58:07 -06:00
### stop seahub and sefile service
2019-05-21 17:27:10 -06:00
exit 0