Fix ntfy notification hooks to use Borgmatic 2.0 environment variables
Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
Replace deprecated argument-based parameter passing with environment variables
and dynamic data retrieval for archive names and error messages.
Changes:
- Remove "{archive_name}" and "{error}" placeholders from config.yaml
- Update ntfy-success.sh to retrieve archive name via borgmatic list
- Update ntfy-error.sh to extract error messages from systemd logs
- Add repository information to both notification types
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -75,12 +75,12 @@ commands:
|
|||||||
when: [create]
|
when: [create]
|
||||||
run:
|
run:
|
||||||
- echo "Exécution hook de succès"
|
- echo "Exécution hook de succès"
|
||||||
- /etc/borgmatic/hooks/ntfy-success.sh "{archive_name}" "{stats}"
|
- /etc/borgmatic/hooks/ntfy-success.sh
|
||||||
|
|
||||||
- after: error
|
- after: error
|
||||||
run:
|
run:
|
||||||
- echo "Exécution hook d'erreur"
|
- echo "Exécution hook d'erreur"
|
||||||
- /etc/borgmatic/hooks/ntfy-error.sh "{error}"
|
- /etc/borgmatic/hooks/ntfy-error.sh
|
||||||
|
|
||||||
# Commandes PostgreSQL/MySQL si nécessaire
|
# Commandes PostgreSQL/MySQL si nécessaire
|
||||||
# postgresql_databases:
|
# postgresql_databases:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Hook Borgmatic - Notification d'erreur via ntfy
|
# Hook Borgmatic - Notification d'erreur via ntfy
|
||||||
# Arguments: $1 = error message
|
# Borgmatic 2.0 utilise des variables d'environnement
|
||||||
#
|
#
|
||||||
|
|
||||||
# Charger les variables d'environnement
|
# Charger les variables d'environnement
|
||||||
@@ -9,7 +9,12 @@ if [ -f /etc/borgmatic/.env ]; then
|
|||||||
source /etc/borgmatic/.env
|
source /etc/borgmatic/.env
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ERROR_MSG="${1:-Erreur inconnue}"
|
# 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
|
# Envoyer notification d'erreur
|
||||||
curl -s -u "$NTFY_USER" \
|
curl -s -u "$NTFY_USER" \
|
||||||
@@ -19,6 +24,7 @@ curl -s -u "$NTFY_USER" \
|
|||||||
-d "Le backup a échoué !
|
-d "Le backup a échoué !
|
||||||
Erreur: ${ERROR_MSG}
|
Erreur: ${ERROR_MSG}
|
||||||
Date: $(date '+%Y-%m-%d %H:%M:%S')
|
Date: $(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
Repository: ${BORG_REPO}
|
||||||
Vérifiez les logs: journalctl -u borgmatic.service -n 50" \
|
Vérifiez les logs: journalctl -u borgmatic.service -n 50" \
|
||||||
"$NTFY_URL"
|
"$NTFY_URL"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Hook Borgmatic - Notification de succès via ntfy
|
# Hook Borgmatic - Notification de succès via ntfy
|
||||||
# Arguments: $1 = archive_name, $2 = stats
|
# Borgmatic 2.0 utilise des variables d'environnement
|
||||||
#
|
#
|
||||||
|
|
||||||
# Charger les variables d'environnement
|
# Charger les variables d'environnement
|
||||||
@@ -9,12 +9,12 @@ if [ -f /etc/borgmatic/.env ]; then
|
|||||||
source /etc/borgmatic/.env
|
source /etc/borgmatic/.env
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ARCHIVE_NAME="${1:-inconnu}"
|
# Récupérer le nom de la dernière archive créée
|
||||||
STATS="${2:-}"
|
# Borgmatic 2.0 expose BORG_REPO et autres variables d'environnement
|
||||||
|
ARCHIVE_NAME=$(borgmatic list --last 1 --short 2>/dev/null | tail -1)
|
||||||
# Extraire la taille depuis les stats si disponible
|
if [ -z "$ARCHIVE_NAME" ]; then
|
||||||
# Borgmatic passe les stats en JSON, on peut parser ou utiliser directement
|
ARCHIVE_NAME="dernière archive"
|
||||||
SIZE="voir logs pour détails"
|
fi
|
||||||
|
|
||||||
# Envoyer notification de succès
|
# Envoyer notification de succès
|
||||||
curl -s -u "$NTFY_USER" \
|
curl -s -u "$NTFY_USER" \
|
||||||
@@ -23,7 +23,8 @@ curl -s -u "$NTFY_USER" \
|
|||||||
-H "Tags: white_check_mark,backup" \
|
-H "Tags: white_check_mark,backup" \
|
||||||
-d "Backup terminé avec succès.
|
-d "Backup terminé avec succès.
|
||||||
Archive: ${ARCHIVE_NAME}
|
Archive: ${ARCHIVE_NAME}
|
||||||
Date: $(date '+%Y-%m-%d %H:%M:%S')" \
|
Date: $(date '+%Y-%m-%d %H:%M:%S')
|
||||||
|
Repository: ${BORG_REPO}" \
|
||||||
"$NTFY_URL"
|
"$NTFY_URL"
|
||||||
|
|
||||||
echo "Notification de succès envoyée à ntfy"
|
echo "Notification de succès envoyée à ntfy"
|
||||||
|
|||||||
Reference in New Issue
Block a user