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

@@ -1,4 +1,4 @@
.PHONY: help up down restart logs logs-all ps shell db-shell redis-shell occ backup restore update health check-health recover clean permissions
.PHONY: help up down restart logs logs-all ps shell db-shell redis-shell occ backup restore update health check-health recover clean permissions cron-logs cron-status
include .env
export
@@ -47,6 +47,10 @@ help:
@echo " → Docker, containers, Nextcloud, DB, Redis"
@echo " → Espace disque, backups, logs"
@echo ""
@echo "Automatisation:"
@echo " make cron-status - Afficher le statut et le planning des backups auto"
@echo " make cron-logs - Afficher les logs des tâches cron"
@echo ""
@echo "Outils:"
@echo " make occ <cmd> - Exécuter une commande OCC Nextcloud"
@echo " make shell - Ouvrir un shell dans le container Nextcloud"
@@ -124,6 +128,30 @@ clean:
@$(DOCKER_COMPOSE) exec -T nextcloud php occ files:cleanup 2>/dev/null && echo "✅ Fichiers orphelins nettoyés" || true
@echo "✅ Nettoyage terminé"
cron-status:
@echo "=== Statut du service de backup automatique ==="
@echo ""
@echo "Container backup-cron:"
@$(DOCKER_COMPOSE) ps backup-cron
@echo ""
@echo "Planning des tâches:"
@$(DOCKER_COMPOSE) exec -T backup-cron cat /etc/crontabs/root 2>/dev/null | grep -v "^#" | grep -v "^$$" || echo "⚠ Container non démarré"
@echo ""
@echo "Heure du container:"
@$(DOCKER_COMPOSE) exec -T backup-cron date 2>/dev/null || echo "⚠ Container non démarré"
cron-logs:
@echo "=== Logs des tâches automatiques ==="
@echo ""
@echo "Logs de backup (10 dernières lignes):"
@tail -n 10 ./logs/cron_backup.log 2>/dev/null || echo "Aucun log de backup"
@echo ""
@echo "Logs de health check (10 dernières lignes):"
@tail -n 10 ./logs/cron_health.log 2>/dev/null || echo "Aucun log de health check"
@echo ""
@echo "Logs de nettoyage (10 dernières lignes):"
@tail -n 10 ./logs/cron_clean.log 2>/dev/null || echo "Aucun log de nettoyage"
# Catch-all target pour permettre les arguments aux commandes occ et restore
%:
@: