From eba6edff6c9724a4d6178e3ebad3b99346f5618e Mon Sep 17 00:00:00 2001 From: Tobias Strobel Date: Wed, 29 Sep 2021 21:09:15 +0200 Subject: [PATCH] Add Nextcloud Backup to script --- helios/external-backup.sh | 90 +++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/helios/external-backup.sh b/helios/external-backup.sh index 5193d66..095cb02 100644 --- a/helios/external-backup.sh +++ b/helios/external-backup.sh @@ -9,9 +9,6 @@ # LOGFILE="$(mktemp)" -GOTIFYURL="https://push.strobeto.de/message?token=Anks7VaBnyf7jCB" -HCURL="https://hc.strobeto.de/ping/615c0b9b-077d-46b4-913b-b70d911dab27" - SERVER="$(hostname)" # ### Konfiguration @@ -22,9 +19,6 @@ HDMINFREE=90 # Welcher Pfad soll gesichert werden? SRC_PATH=/ -# Unter welchem Pfad wird gesichert? -DATA_PATH=/mnt/backupone - setLED () { # Set LED status echo heartbeat > "/sys/class/leds/helios64:blue:usb3/trigger" @@ -76,7 +70,7 @@ notify () { ;; error) NOTIFY_TITLE+="Backup has ERRORS" - NOTIFY_MESSAGE="Exit code $STATUSCODE. See logs attached to healthchecks for more information." + NOTIFY_MESSAGE="Exit code $2. See logs attached to healthchecks for more information." NOTIFY_PRIORITY=8 ;; *) @@ -104,6 +98,34 @@ fi } basicChecks () { + CONFFILE=~/.config/externalbackup.conf + + if ! [ -f $CONFFILE ] ; then + cat >>$CONFFILE < 2&>1 + + echo "Starting nextcloud backup..." + $NCOCC maintenance:mode --on + + echo "Backup Nextcloud DB" + PGPASSWORD=$DBPASSWORD pg_dump $DBNAME -h $DBHOST -U $DBUSER -f "$NCDUMPSDIR/nextcloud-sqlbkp_`date +"%Y-%m-%d-%H-%M-%S"`.bak" + + + echo "Backup $NCDATADIR" + rsync -aAXHh --stats --numeric-ids --noatime --delete --delete-excluded $NCDATADIR/ $DATA_PATH/"$SERVER"/daily.0$NCDATADIR + + STATUSCODE=$? + + # Rückgabewert prüfen. + # 0 = fehlerfrei, + # 24 ist harmlos; tritt auf, wenn während der Laufzeit + # von rsync noch (/tmp?) Dateien verändert oder gelöscht wurden. + # Alles andere ist fatal -- siehe man (1) rsync + if [ "$STATUSCODE" -ne 24 ] && [ "$STATUSCODE" -ne 0 ] ; then + echo "Fatal: rsync for Nextcloud finished on $SERVER with errors!" + healthchecksFinish "$STATUSCODE" + notify error "$STATUSCODE" + $NCOCC maintenance:mode --off + exit "$STATUSCODE" + fi + echo "Finished nextcloud backup..." + $NCOCC maintenance:mode --off +} + backup () { + backupNC + echo "Starting rsync backup from $SERVER..." rsync -aAXHh --stats --numeric-ids --noatime --delete --delete-excluded \ - --include={"/mnt/storage","/mnt/storage/nc_data**","/mnt/storage/media**","/mnt/storage/backup**"} \ + --include={"/mnt/storage","/mnt/storage/media**","/mnt/storage/backup**"} \ --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/.snapshots"} \ $SRC_PATH $DATA_PATH/"$SERVER"/daily.0 @@ -188,10 +260,10 @@ backup () { exec > >(tee -i "${LOGFILE}") exec 2>&1 +basicChecks ${1} healthchecksStart notify start setLED -basicChecks backup rotate healthchecksFinish