Files
agence66-nextcloud-docker/docker-compose.yml
BeauTroll e055d708a5 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>
2025-12-18 02:24:48 +01:00

112 lines
2.8 KiB
YAML

services:
nextcloud:
image: nextcloud:latest
restart: unless-stopped
ports:
- "127.0.0.1:8888:80"
volumes:
- ./data:/var/www/html
environment:
# Database
- MYSQL_HOST=db
- MYSQL_DATABASE=${MYSQL_DATABASE:-nextcloud}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
# Domaine
- NEXTCLOUD_TRUSTED_DOMAINS=${NEXTCLOUD_DOMAIN}
- TRUSTED_PROXIES=${TRUSTED_PROXIES:-}
- OVERWRITEPROTOCOL=${OVERWRITE_PROTOCOL:-http}
- OVERWRITEHOST=${OVERWRITE_HOST:-}
- OVERWRITECLIURL=${OVERWRITE_CLI_URL:-}
# Redis
- REDIS_HOST=redis
- REDIS_HOST_PASSWORD=${REDIS_HOST_PASSWORD}
# PHP
- PHP_MEMORY_LIMIT=4096M
- PHP_UPLOAD_MAX_FILESIZE=2G
- PHP_POST_MAX_SIZE=2G
- PHP_MAX_EXECUTION_TIME=1800
- PHP_MAX_INPUT_TIME=1800
# Apache
- APACHE_BODY_LIMIT=2147483648
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/status.php"]
interval: 30s
timeout: 10s
retries: 3
depends_on:
db:
condition: service_healthy
redis:
condition: service_started
networks:
- nextcloud-net
- traefik-net
redis:
image: redis:alpine
restart: unless-stopped
command: redis-server --requirepass ${REDIS_HOST_PASSWORD} --maxmemory 512mb --maxmemory-policy allkeys-lru
networks:
- nextcloud-net
cron:
image: nextcloud:latest
restart: always
volumes_from:
- nextcloud
entrypoint: /cron.sh
depends_on:
- nextcloud
- db
- redis
networks:
- nextcloud-net
backup-cron:
build: ./cron
restart: unless-stopped
volumes:
# Monter le projet complet pour accéder aux scripts
- .:/project
# Monter Docker socket pour exécuter les commandes docker-compose
- /var/run/docker.sock:/var/run/docker.sock
# Partager les volumes avec nextcloud pour les backups
- ./data:/var/www/html
- ./db:/var/lib/mysql
- ./backups:/project/backups
- ./logs:/logs
environment:
- TZ=Europe/Paris
- COMPOSE_PROJECT_NAME
depends_on:
- nextcloud
- db
networks:
- nextcloud-net
db:
image: mariadb:10.11
restart: unless-stopped
volumes:
- ./db:/var/lib/mysql
- ./db-config/my.cnf:/etc/mysql/conf.d/custom.cnf:ro
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 3
networks:
- nextcloud-net
networks:
nextcloud-net:
driver: bridge
traefik-net:
external: true