Files
agence66-nextcloud-docker/Makefile
BeauTroll 01c0db45f5 feat: enhance Makefile with Docker Compose v2 support and new utilities
Major improvements to the Makefile:

- Auto-detect Docker Compose v2 (docker compose) vs v1 (docker-compose)
- Add new utility commands:
  * make logs-all: View logs from all containers
  * make shell: Open bash in Nextcloud container
  * make db-shell: Open MySQL shell
  * make redis-shell: Open Redis CLI (with password support)
  * make permissions: Fix file permissions
  * make clean: Clean old logs (>30 days) and temp files

- Improve restore command:
  * Now requires FILE= parameter for better UX
  * Shows helpful error with list of available backups
  * Example: make restore FILE=./backups/backup.tar.gz

- Better help organization:
  * New "Monitoring" section
  * Better documentation for all commands
  * More detailed command descriptions

- Simplify health check:
  * Use comprehensive check-health.sh script
  * Remove duplicate check-health target

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-17 20:19:23 +01:00

130 lines
4.6 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
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 "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é"
# Catch-all target pour permettre les arguments aux commandes occ et restore
%:
@: