Compare commits

..

4 Commits

Author SHA1 Message Date
BeauTroll
14cbfab07b Add systemd compatibility and verbose logging to Seafile MySQL backup hook
Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
Enhance the Seafile MySQL dump hook with better debugging capabilities
and systemd service compatibility:
- Redirect all output to syslog for systemd journal integration
- Add Docker socket accessibility check before attempting dumps
- Add detailed logging at each step for troubleshooting
- Improve error handling with explicit exit codes
- Add context information (USER, PWD, HOME) for systemd debugging

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 07:54:06 +01:00
BeauTroll
0ae8cb9e0e Fix Seafile MySQL dump authentication by using root user
Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
Update the Seafile MySQL dump hook to use the root user by default
instead of seafile user, which resolves authentication issues. Add
SEAFILE_MYSQL_USER environment variable for user customization.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-09 13:45:10 +01:00
BeauTroll
9c29cc1bdc Improve Seafile MySQL dump hook with better error handling and debugging
Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
Add comprehensive validation and error messages to the Seafile MySQL backup hook:
- Add timeout (5min) to prevent mysqldump from hanging indefinitely
- Validate SEAFILE_DB_PASSWORD is set before attempting dump
- Verify Docker container exists and is running before execution
- Fix file verification bug (check correct output filename)
- Add detailed logging for easier troubleshooting
- Use set -e for fail-fast behavior

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-09 13:37:30 +01:00
BeauTroll
671347b39d add seafile mysql dump hook
Some checks failed
Deploy Borgmatic Configuration / Deploy to Production Server (push) Has been cancelled
2026-01-09 00:19:11 +01:00
3 changed files with 103 additions and 0 deletions

View File

@@ -37,6 +37,17 @@ NTFY_USER=username:password
# Obtenue depuis Uptime Kuma > Add New Monitor > Type: Push # Obtenue depuis Uptime Kuma > Add New Monitor > Type: Push
UPTIME_KUMA_PUSH_URL=http://uptime-kuma:3001/api/push/YOUR_KEY_HERE UPTIME_KUMA_PUSH_URL=http://uptime-kuma:3001/api/push/YOUR_KEY_HERE
# ============================================
# BASES DE DONNÉES
# ============================================
# Mot de passe MySQL pour Seafile (généralement MYSQL_ROOT_PASSWORD)
SEAFILE_DB_PASSWORD=your-seafile-mysql-root-password
# Utilisateur MySQL pour les dumps (par défaut: root)
# Décommenter et modifier si vous utilisez un autre utilisateur
# SEAFILE_MYSQL_USER=seafile
# ============================================ # ============================================
# OPTIONS AVANCÉES # OPTIONS AVANCÉES
# ============================================ # ============================================

View File

@@ -76,6 +76,7 @@ commands:
when: [create] when: [create]
run: run:
- echo "Backup démarré" - echo "Backup démarré"
- /etc/borgmatic/hooks/seafile-docker-mysql-backup.sh
- after: action - after: action
when: [create] when: [create]

View File

@@ -0,0 +1,91 @@
#!/bin/bash
# Hook Borgmatic - Dump MySQL Seafile dockerisé avant backup
set -e # Arrêter en cas d'erreur
BACKUP_DIR="/opt/seafile/backups/mysql"
DATE=$(date +%Y%m%d-%H%M)
SEAFILE_CONTAINER="seafile" # Nom de votre conteneur Seafile
MYSQL_CONTAINER="seafile-mysql" # Ou le nom de votre conteneur MySQL
# Log pour debug systemd
exec 1> >(logger -t seafile-backup -p user.info)
exec 2> >(logger -t seafile-backup -p user.error)
echo "[$(date)] Démarrage dump MySQL Seafile..."
echo "Contexte: USER=$USER, PWD=$PWD, HOME=$HOME"
# Créer le répertoire de backup
mkdir -p "$BACKUP_DIR"
echo "✓ Répertoire de backup: $BACKUP_DIR"
# Charger les identifiants depuis .env
if [ -f /etc/borgmatic/.env ]; then
source /etc/borgmatic/.env
echo "✓ Variables chargées depuis /etc/borgmatic/.env"
else
echo "⚠️ /etc/borgmatic/.env non trouvé"
fi
# Utilisateur MySQL (par défaut root, configurable via .env)
MYSQL_USER="${SEAFILE_MYSQL_USER:-root}"
# Vérifier que le mot de passe est défini
if [ -z "$SEAFILE_DB_PASSWORD" ]; then
echo "❌ SEAFILE_DB_PASSWORD n'est pas défini dans /etc/borgmatic/.env"
exit 1
fi
echo "✓ Utilisateur MySQL: $MYSQL_USER"
echo "✓ Mot de passe MySQL défini"
# Vérifier l'accès à Docker
echo "Test accès Docker..."
if ! docker info >/dev/null 2>&1; then
echo "❌ Impossible d'accéder à Docker (socket /var/run/docker.sock)"
exit 1
fi
echo "✓ Docker accessible"
# Vérifier que le conteneur existe et tourne
echo "Recherche du conteneur $MYSQL_CONTAINER..."
if ! docker ps --format '{{.Names}}' | grep -q "^${MYSQL_CONTAINER}$"; then
echo "❌ Conteneur $MYSQL_CONTAINER non trouvé ou arrêté"
echo "Conteneurs disponibles:"
docker ps --format " - {{.Names}}"
exit 1
fi
echo "✓ Conteneur $MYSQL_CONTAINER trouvé"
# Dump unique avec toutes les bases
DUMP_FILE="$BACKUP_DIR/seafile-all-$DATE.sql"
echo "→ Lancement du dump MySQL vers: $DUMP_FILE"
echo "→ Commande: docker exec $MYSQL_CONTAINER mysqldump -u $MYSQL_USER ..."
# Utiliser une approche sans redirection 2>&1 qui peut bloquer
set +e # Désactiver temporairement set -e pour capturer le code de sortie
timeout 300 docker exec "$MYSQL_CONTAINER" mysqldump \
-u "$MYSQL_USER" -p"${SEAFILE_DB_PASSWORD}" \
--single-transaction --quick --databases \
ccnet_db seafile_db seahub_db > "$DUMP_FILE" 2>&1
DUMP_EXIT_CODE=$?
set -e
echo "→ Code de sortie mysqldump: $DUMP_EXIT_CODE"
if [ $DUMP_EXIT_CODE -eq 0 ] && [ -f "$DUMP_FILE" ] && [ -s "$DUMP_FILE" ]; then
SIZE=$(du -h "$DUMP_FILE" | cut -f1)
echo "✓ Dump créé: seafile-all-$DATE.sql ($SIZE)"
else
echo "❌ Échec du dump (code sortie: $DUMP_EXIT_CODE)"
[ -f "$DUMP_FILE" ] && echo "Taille fichier: $(stat -f %z "$DUMP_FILE" 2>/dev/null || stat -c %s "$DUMP_FILE") bytes"
exit 1
fi
# Nettoyer les anciens dumps (garder 7 jours)
DELETED=$(find "$BACKUP_DIR" -name "*.sql" -mtime +7 -delete -print | wc -l)
if [ "$DELETED" -gt 0 ]; then
echo "🗑️ $DELETED ancien(s) dump(s) supprimé(s)"
fi
echo "[$(date)] ✅ Dump MySQL Seafile terminé avec succès"
exit 0