SnapRAID Automation - Cron Jobs et Monitoring
Automatisation des tâches SnapRAID (sync, scrub) et monitoring proactif.
Informations
| Tâche | Fréquence Recommandée | Durée | Impact Système |
|---|---|---|---|
| Sync | Hebdomadaire | 2-5 min | I/O moyen |
| Scrub | Mensuel | 10-30 min | I/O élevé |
| Status | Quotidien | <5 sec | Négligeable |
| SMART check | Quotidien | <10 sec | Négligeable |
Script Automation Complet
Script sync-snapraid.sh
Path: /usr/local/bin/sync-snapraid.sh
Fonction: Synchronisation automatique hebdomadaire avec vérifications SMART, gestion des seuils, et notifications
Fonctionnalités: - Vérification SMART pré-sync et détection erreurs disques - Analyse diff avec seuil configurable (500 fichiers par défaut) - Lock file pour éviter exécutions simultanées - Scrub partiel 10% après sync réussi - Logging détaillé et notifications (ntfy.sh/email) - Nettoyage automatique logs >30 jours
Installation Cron (Hebdomadaire)
# Ajouter à cron (dimanche 3h00)
(crontab -l 2>/dev/null; echo "0 3 * * 0 /usr/local/bin/sync-snapraid.sh") | crontab -
# Vérifier cron
crontab -l | grep snapraid
# 0 3 * * 0 /usr/local/bin/sync-snapraid.sh ✓
Pourquoi dimanche 3h00 :
- Activité serveur faible (nuit)
- Après accumulation semaine de nouveaux contenus
- Avant début semaine (protection fraîche)
Test Script Manuel
# Exécuter manuellement (vérifier fonctionnement)
/usr/local/bin/sync-snapraid.sh
# Vérifier logs
tail -f /var/log/snapraid-sync.log
Script Scrub Mensuel
Script scrub-snapraid.sh
Path: /usr/local/bin/scrub-snapraid.sh
Fonction: Vérification intégrité complète (100% données) mensuelle
Fonctionnalités: - Scrub complet 100% de l'array parity - Détection et signalement erreurs intégrité - Notifications email en cas d'erreurs
Configuration cron:
Monitoring Proactif
Script Health Check Quotidien
Path: /usr/local/bin/snapraid-health.sh
Fonction: Surveillance santé array et alertes proactives
Fonctionnalités: - Vérification SMART quotidienne avec détection erreurs - Monitoring température disques (alerte si >50°C) - Surveillance âge dernière sync (alerte si >14 jours) - Rapport status array complet
Configuration cron:
Vérification:
Dashboard Monitoring (Optionnel)
Intégration Homepage Dashboard
Fichier : /mnt/lxc-data/docker-101/homepage/services/proxmox.yaml
- Storage:
- SnapRAID:
icon: snapraid.png
href: file:///var/log/snapraid-sync.log
description: Parity Protection
widget:
type: customapi
url: http://localhost:3000/snapraid-status
mappings:
- field: last_sync
label: Last Sync
- field: health
label: Health
API Status (Script CGI Simple)
Path: /usr/local/bin/snapraid-api.sh
Fonction: Endpoint JSON pour intégration dashboard (Homepage)
Fonctionnalités: - Export JSON status (last_sync, health, status) - Compatible Homepage widget customapi - Calcul âge sync en heures
Utilisation:
Alertes et Notifications
Configuration ntfy.sh (Gratuit)
# Installer curl si absent
apt install curl
# Tester notification
curl -d "SnapRAID test notification" https://ntfy.sh/homelab-snapraid
# Ajouter à scripts:
notify() {
curl -d "$1" https://ntfy.sh/homelab-snapraid
}
Application mobile : Installer ntfy app (Android/iOS), s'abonner topic homelab-snapraid
Configuration Email (Alternative)
# Installer mailutils
apt install mailutils
# Configurer SMTP (ex: Gmail)
# Éditer /etc/postfix/main.cf
# Tester
echo "Test email" | mail -s "SnapRAID Test" admin@example.com
Logs et Historique
Centralisation Logs
# Tous logs SnapRAID dans /var/log/snapraid/
mkdir -p /var/log/snapraid
# Rotation logs automatique
cat > /etc/logrotate.d/snapraid << 'EOF'
/var/log/snapraid/*.log {
weekly
rotate 12
compress
delaycompress
missingok
notifempty
}
EOF
Analyse Logs Rapide
# Dernières exécutions sync
grep "Sync Complete" /var/log/snapraid-sync.log | tail -5
# Erreurs récentes
grep -i "error\|fail" /var/log/snapraid-*.log | tail -20
# Statistiques sync (durée)
grep "Sync completed in" /var/log/snapraid-sync.log | tail -10
Performance Monitoring
Métriques Clés
Path: /usr/local/bin/snapraid-metrics.sh
Fonction: Export métriques performance et statistiques array
Métriques collectées: - Taille fichier parity - Nombre fichiers protégés - Niveau fragmentation - Âge dernière sync (jours)
Exemple sortie:
/usr/local/bin/snapraid-metrics.sh
# Parity size: 8.2T
# Protected files: 142567
# Fragmented files: 23
# Sync age: 2 days
Troubleshooting Automation
Problème : Sync Échoue en Cron
Symptôme : Cron email "snapraid command not found"
Cause : PATH incomplet dans environnement cron
Solution :
# Éditer cron avec PATH complet
crontab -e
# Ajouter en haut:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Ou utiliser path absolu dans script:
/usr/local/bin/snapraid sync
Problème : Lock File Bloqué
Symptôme : Script refuse lancer "Another sync running"
Cause : Lock file non supprimé (interruption précédente)
Solution :
# Vérifier processus snapraid actif
ps aux | grep snapraid
# Si aucun processus, supprimer lock
rm /var/run/snapraid-sync.lock
# Relancer script
/usr/local/bin/sync-snapraid.sh
Problème : Logs Saturent Disque
Symptôme : /var/log/snapraid-*.log > 10 GB
Solution :
# Nettoyer logs anciens
find /var/log -name "snapraid-*.log" -mtime +30 -delete
# Vérifier rotation active
cat /etc/logrotate.d/snapraid
# Forcer rotation manuelle
logrotate -f /etc/logrotate.d/snapraid
Checklist Automation
Configuration Initiale
- Script sync-snapraid.sh créé et testé
- Cron hebdomadaire configuré (dimanche 3h)
- Script scrub mensuel configuré (1er du mois)
- Health check quotidien actif (6h)
- Notifications configurées (ntfy/email)
- Rotation logs activée
Vérification Mensuelle
- Vérifier logs sync (aucune erreur)
- Vérifier scrub exécuté (100% données)
- Vérifier SMART status (tous disques PASSED)
- Vérifier sync age (<7 jours)
- Tester notifications (envoyer test)
Ajustements Performance
Si sync trop long (>30 min) :
- Réduire
SCRUB_PERCENTAGEà 5% après sync - Exécuter scrub 100% séparément (mensuel)
Si charge système trop élevée :
- Décaler horaire cron (éviter heures activité)
- Utiliser
nice -n 15 snapraid sync(priorité basse) - Réduire fréquence (bi-hebdomadaire vs hebdomadaire)
Ressources
- SnapRAID Scripts Collection - Scripts communautaires
- Zack Reed SnapRAID Script - Script populaire
- ntfy.sh Documentation - Notifications push
Voir Aussi
- SnapRAID - Configuration de base
- SnapRAID Recovery - Procédures récupération
- Maintenance - Monitoring global système
Dernière mise à jour : 27 janvier 2026