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

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:
BeauTroll
2025-12-17 06:42:14 +01:00
parent 25b0a2fcfa
commit b2beeb3334
3 changed files with 19 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/bash
#
# 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
@@ -9,12 +9,12 @@ if [ -f /etc/borgmatic/.env ]; then
source /etc/borgmatic/.env
fi
ARCHIVE_NAME="${1:-inconnu}"
STATS="${2:-}"
# Extraire la taille depuis les stats si disponible
# Borgmatic passe les stats en JSON, on peut parser ou utiliser directement
SIZE="voir logs pour détails"
# Récupérer le nom de la dernière archive créée
# Borgmatic 2.0 expose BORG_REPO et autres variables d'environnement
ARCHIVE_NAME=$(borgmatic list --last 1 --short 2>/dev/null | tail -1)
if [ -z "$ARCHIVE_NAME" ]; then
ARCHIVE_NAME="dernière archive"
fi
# Envoyer notification de succès
curl -s -u "$NTFY_USER" \
@@ -23,7 +23,8 @@ curl -s -u "$NTFY_USER" \
-H "Tags: white_check_mark,backup" \
-d "Backup terminé avec succès.
Archive: ${ARCHIVE_NAME}
Date: $(date '+%Y-%m-%d %H:%M:%S')" \
Date: $(date '+%Y-%m-%d %H:%M:%S')
Repository: ${BORG_REPO}" \
"$NTFY_URL"
echo "Notification de succès envoyée à ntfy"