#!/bin/bash # # Hook Borgmatic - Notification d'erreur via ntfy # Borgmatic 2.0 utilise des variables d'environnement # # Charger les variables d'environnement if [ -f /etc/borgmatic/.env ]; then source /etc/borgmatic/.env fi # Récupérer les dernières lignes d'erreur depuis les logs ERROR_MSG=$(journalctl -u borgmatic.service -n 10 --no-pager | tail -5 | sed 's/^.*borgmatic: //') if [ -z "$ERROR_MSG" ]; then ERROR_MSG="Erreur inconnue - vérifiez les logs" fi # Envoyer notification d'erreur curl -s -u "$NTFY_USER" \ -H "Title: ❌ Backup échoué" \ -H "Priority: high" \ -H "Tags: x,backup,alert" \ -d "Le backup a échoué ! Erreur: ${ERROR_MSG} Date: $(date '+%Y-%m-%d %H:%M:%S') Repository: ${BORG_REPO} Vérifiez les logs: journalctl -u borgmatic.service -n 50" \ "$NTFY_URL" echo "Notification d'erreur envoyée à ntfy" exit 0