backup2home: jetzt mit korrekter Gotify Nachricht bei Fehlern
SSH-Verbindung wird ebenfalls geprüft
This commit is contained in:
@@ -6,6 +6,7 @@ SOURCE="/home/stefan"
|
||||
|
||||
# Passphrase sicher aus Datei lesen
|
||||
export BORG_PASSCOMMAND="cat /home/stefan/.config/borg/passphrase"
|
||||
export GOTIFY_TOKEN=$(cat /home/stefan/.config/gotify/token)
|
||||
|
||||
EXCLUDES=(
|
||||
"/home/stefan/docker/privatebin"
|
||||
@@ -21,7 +22,23 @@ EXCLUDES=(
|
||||
|
||||
BACKUP_NAME="backup-$(date +%Y-%m-%d_%H-%M-%S)"
|
||||
GOTIFY_URL="https://gotify.nauheimtech.de"
|
||||
GOTIFY_TOKEN=${GOTIFY_PW}
|
||||
|
||||
# Funktion zum Senden einer Nachricht an Gotify
|
||||
send_gotify_notification() {
|
||||
local message=$1
|
||||
local priority=$2
|
||||
curl -s -X POST "$GOTIFY_URL/message" \
|
||||
-H "X-Gotify-Key: $GOTIFY_TOKEN" \
|
||||
-d "title=Backup Fehler&message=$message&priority=$priority"
|
||||
}
|
||||
|
||||
# Teste SSH-Verbindung
|
||||
echo "===== Teste SSH-Verbindung: $(date) ====="
|
||||
if ! ssh -o BatchMode=yes -o ConnectTimeout=10 stefan@172.25.28.34 "echo Verbindung erfolgreich"; then
|
||||
send_gotify_notification "Backup fehlgeschlagen: Keine SSH-Verbindung möglich" 10
|
||||
echo "FEHLER: Keine SSH-Verbindung möglich am $(date)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Backup starten
|
||||
echo "===== Backup gestartet: $(date) ====="
|
||||
@@ -31,12 +48,8 @@ BACKUP_EXIT=$?
|
||||
|
||||
# Falls das Backup fehlschlägt, Nachricht an Gotify senden
|
||||
if [ $BACKUP_EXIT -ne 0 ]; then
|
||||
MESSAGE="Backup fehlgeschlagen: $BACKUP_NAME"
|
||||
PRIORITY=10
|
||||
send_gotify_notification "Backup fehlgeschlagen: $BACKUP_NAME" 10
|
||||
echo "FEHLER: Backup fehlgeschlagen ($BACKUP_NAME) am $(date)"
|
||||
curl -s -X POST "$GOTIFY_URL/message" \
|
||||
-H "X-Gotify-Key: $GOTIFY_TOKEN" \
|
||||
-d "title=Backup Fehler&message=$MESSAGE&priority=$PRIORITY"
|
||||
fi
|
||||
|
||||
# Alte Backups bereinigen
|
||||
|
||||
Reference in New Issue
Block a user