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>
158 lines
5.8 KiB
Makefile
158 lines
5.8 KiB
Makefile
.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
|
|
|
|
# Detect Docker Compose command
|
|
DOCKER_COMPOSE := $(shell command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1 && echo "docker compose" || echo "docker-compose")
|
|
|
|
help:
|
|
@echo "Nextcloud Docker - Commandes disponibles:"
|
|
@echo ""
|
|
@echo "Services:"
|
|
@echo " make up - Démarrer tous les services Docker"
|
|
@echo " make down - Arrêter et supprimer les containers"
|
|
@echo " make restart - Redémarrer tous les services"
|
|
@echo " make ps - Lister les containers actifs"
|
|
@echo " make logs - Afficher les logs Nextcloud en temps réel"
|
|
@echo " make logs-all - Afficher les logs de tous les containers"
|
|
@echo ""
|
|
@echo "Maintenance:"
|
|
@echo " make backup - Backup complet (DB + fichiers + config)"
|
|
@echo " → Active mode maintenance"
|
|
@echo " → Sauvegarde MariaDB, config, données, apps"
|
|
@echo " → Désactive mode maintenance"
|
|
@echo " → Archive dans ./backups/"
|
|
@echo ""
|
|
@echo " make update - Mise à jour Nextcloud (avec backup auto)"
|
|
@echo " → Backup de sécurité automatique"
|
|
@echo " → Pull nouvelle image Docker"
|
|
@echo " → Restart avec nouvelle version"
|
|
@echo " → Upgrade base de données"
|
|
@echo " → Optimisations post-update"
|
|
@echo ""
|
|
@echo " make restore FILE=<backup.tar.gz>"
|
|
@echo " - Restaurer depuis un backup"
|
|
@echo " → Arrêt des services"
|
|
@echo " → Restauration DB + fichiers"
|
|
@echo " → Redémarrage et réparation"
|
|
@echo ""
|
|
@echo " make recover - Récupération après erreur"
|
|
@echo " → Arrêt/nettoyage des containers"
|
|
@echo " → Redémarrage propre"
|
|
@echo " → Désactivation mode maintenance"
|
|
@echo ""
|
|
@echo "Monitoring:"
|
|
@echo " make health - Health check complet du système"
|
|
@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"
|
|
@echo " make db-shell - Ouvrir un shell MySQL/MariaDB"
|
|
@echo " make redis-shell - Ouvrir un shell Redis"
|
|
@echo " make permissions - Réparer les permissions des fichiers"
|
|
@echo " make clean - Nettoyer les logs et fichiers temporaires"
|
|
|
|
up:
|
|
$(DOCKER_COMPOSE) up -d
|
|
|
|
down:
|
|
$(DOCKER_COMPOSE) down
|
|
|
|
restart:
|
|
$(DOCKER_COMPOSE) restart
|
|
|
|
logs:
|
|
$(DOCKER_COMPOSE) logs -f --tail=100 nextcloud
|
|
|
|
logs-all:
|
|
$(DOCKER_COMPOSE) logs -f --tail=50
|
|
|
|
ps:
|
|
$(DOCKER_COMPOSE) ps
|
|
|
|
shell:
|
|
$(DOCKER_COMPOSE) exec nextcloud /bin/bash
|
|
|
|
db-shell:
|
|
$(DOCKER_COMPOSE) exec db mysql -u"$$MYSQL_USER" -p"$$MYSQL_PASSWORD" "$$MYSQL_DATABASE"
|
|
|
|
redis-shell:
|
|
@if [ -n "$(REDIS_HOST_PASSWORD)" ]; then \
|
|
$(DOCKER_COMPOSE) exec redis redis-cli -a "$(REDIS_HOST_PASSWORD)"; \
|
|
else \
|
|
$(DOCKER_COMPOSE) exec redis redis-cli; \
|
|
fi
|
|
|
|
occ:
|
|
@bash scripts/occ.sh $(filter-out $@,$(MAKECMDGOALS))
|
|
|
|
backup:
|
|
@bash scripts/backup.sh
|
|
|
|
restore:
|
|
@if [ -z "$(FILE)" ]; then \
|
|
echo "❌ Erreur: Spécifiez le fichier de backup avec FILE=<fichier>"; \
|
|
echo "Exemple: make restore FILE=./backups/nextcloud_backup_20231217_123456.tar.gz"; \
|
|
echo ""; \
|
|
echo "Backups disponibles:"; \
|
|
find ./backups -name "nextcloud_backup_*.tar.gz" -type f -printf '%T+ %p\n' 2>/dev/null | sort -r | head -5; \
|
|
exit 1; \
|
|
fi
|
|
@bash scripts/restore.sh "$(FILE)"
|
|
|
|
update:
|
|
@bash scripts/update.sh
|
|
|
|
health:
|
|
@bash scripts/check-health.sh
|
|
|
|
recover:
|
|
@bash scripts/recover.sh
|
|
|
|
permissions:
|
|
@echo "Réparation des permissions..."
|
|
$(DOCKER_COMPOSE) exec -u root nextcloud chown -R www-data:www-data /var/www/html/data /var/www/html/config /var/www/html/custom_apps
|
|
@echo "✅ Permissions réparées"
|
|
|
|
clean:
|
|
@echo "Nettoyage des logs et fichiers temporaires..."
|
|
@find ./logs -type f -mtime +30 -delete 2>/dev/null && echo "✅ Logs > 30 jours supprimés" || true
|
|
@rm -f /tmp/nextcloud_*.lock 2>/dev/null && echo "✅ Fichiers lock supprimés" || true
|
|
@$(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
|
|
%:
|
|
@:
|