feat: add automated backup system with Docker-based cron

Implement a dedicated Docker container (backup-cron) for automated daily
backups and maintenance tasks, eliminating the need for host cron configuration.

New features:
- backup-cron service: Alpine-based container with Docker CLI and cron
- Automated daily backup at 5:00 AM (Europe/Paris timezone)
- Automated health check at 6:00 AM (after backup)
- Weekly log cleanup on Sundays at 3:00 AM (removes logs >30 days)

Files added:
- cron/Dockerfile: Alpine Linux with docker-cli, bash, and tzdata
- cron/entrypoint.sh: Starts crond and displays configuration
- cron/crontab: Scheduled tasks configuration
- cron/README.md: Complete documentation for automated backups
- scripts/clean-old-logs.sh: Automated log cleanup script

Makefile enhancements:
- make cron-status: Display backup automation status and schedule
- make cron-logs: View logs from automated tasks

Configuration improvements:
- Auto-detect COMPOSE_PROJECT_NAME from directory name (portable)
- Fix df command to use POSIX format (-P flag) for consistent output
- Updated .env.example with COMPOSE_PROJECT_NAME documentation

Benefits:
- No host cron configuration required
- Portable across different environments
- Automatic timezone handling
- Integrated with existing backup/health check scripts
- Logs all automated tasks for monitoring

🤖 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-18 02:24:48 +01:00
parent a7c14f9000
commit e055d708a5
9 changed files with 284 additions and 2 deletions

View File

@@ -114,7 +114,8 @@ if [ -z "$REQUIRED_SPACE" ] || [ "$REQUIRED_SPACE" = "0" ]; then
fi
# Obtenir l'espace disponible (enlever les espaces/newlines)
AVAILABLE_SPACE=$(df -B1 "$BACKUP_DIR" | awk 'NR==2 {print $4}' | tr -d '[:space:]')
# Utiliser -P pour format POSIX (garantit une ligne par système de fichiers)
AVAILABLE_SPACE=$(df -P -B1 "$BACKUP_DIR" | awk 'NR==2 {print $4}' | tr -d '[:space:]')
if [ -z "$AVAILABLE_SPACE" ]; then
log "ERROR" "Impossible de déterminer l'espace disque disponible"
exit 1

26
scripts/clean-old-logs.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
# scripts/clean-old-logs.sh - Nettoyage automatique des vieux logs
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
LOG_DIR="./logs"
RETENTION_DAYS=30
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Nettoyage des logs > ${RETENTION_DAYS} jours..."
# Compter les fichiers avant nettoyage
BEFORE=$(find "$LOG_DIR" -type f -name "*.log" 2>/dev/null | wc -l)
# Supprimer les logs plus vieux que RETENTION_DAYS jours
DELETED=$(find "$LOG_DIR" -type f -name "*.log" -mtime +${RETENTION_DAYS} -delete -print 2>/dev/null | wc -l)
# Compter les fichiers après nettoyage
AFTER=$(find "$LOG_DIR" -type f -name "*.log" 2>/dev/null | wc -l)
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Fichiers supprimés: $DELETED"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Fichiers restants: $AFTER"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Nettoyage terminé"