alles geht aber noch aufräumen

This commit is contained in:
2026-02-12 17:38:03 +01:00
parent 58856844ce
commit e8c41d1f64
6 changed files with 78 additions and 8 deletions

View File

@@ -20,6 +20,17 @@ After first `docker compose up`, install the **Redis Object Cache** plugin in WP
The `wp-config.php` already has the `WP_REDIS_HOST` and `WP_REDIS_PORT` constants set.
## Cron
## Backups
Backup script in Cron einbinden nicht vergessen
Backups laufen automatisch im `backup` Container (Standard: täglich um 2:00 Uhr).
Konfigurierbar über `.env`:
- `BACKUP_SCHEDULE` Cron-Ausdruck (Standard: `0 2 * * *`)
- `BACKUP_RETENTION_DAYS` Alte Backups löschen nach X Tagen (Standard: `7`)
Backups landen in `./backups/`. Manuelles Backup auslösen:
```
docker compose exec backup /usr/local/bin/backup.sh
```
Das alte `backup.sh` auf dem Host funktioniert weiterhin für manuelle Backups.

29
backup-container.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/sh
set -e
DATE=$(date +"%Y-%m-%d_%H-%M")
BACKUP_DIR="/backups"
BACKUP_NAME="${DATE}.tar.gz"
mkdir -p "$BACKUP_DIR"
echo "[$(date)] Starting backup..."
echo "Dumping database..."
mariadb-dump --no-tablespaces \
-h db \
-u"$MYSQL_USER" \
-p"$MYSQL_PASSWORD" \
"$MYSQL_DATABASE" > "/tmp/db_dump_${DATE}.sql"
echo "Creating tar.gz archive..."
tar -czf "${BACKUP_DIR}/${BACKUP_NAME}" \
-C /source/wp . \
-C /tmp "db_dump_${DATE}.sql"
rm -f "/tmp/db_dump_${DATE}.sql"
echo "Cleaning up backups older than ${BACKUP_RETENTION_DAYS:-7} days..."
find "$BACKUP_DIR" -name "*.tar.gz" -type f -mtime +${BACKUP_RETENTION_DAYS:-7} -delete
echo "[$(date)] Backup complete: ${BACKUP_DIR}/${BACKUP_NAME}"

2
backup.Dockerfile Normal file
View File

@@ -0,0 +1,2 @@
FROM alpine:latest
RUN apk add --no-cache mariadb-client tar gzip

View File

@@ -25,7 +25,7 @@ services:
restart: unless-stopped
command: redis-server --maxmemory 128mb --maxmemory-policy allkeys-lru
volumes:
- redis_data:/data
- ./redis:/data
networks:
- backend
healthcheck:
@@ -76,10 +76,34 @@ services:
networks:
- frontend
backup:
build:
context: .
dockerfile: backup.Dockerfile
restart: unless-stopped
depends_on:
db:
condition: service_healthy
entrypoint: /bin/sh
command:
- -c
- |
echo "${BACKUP_SCHEDULE:-0 2 * * *} /usr/local/bin/backup.sh" | crontab -
echo "Backup container ready. Schedule: ${BACKUP_SCHEDULE:-0 2 * * *}"
crond -f -l 2
volumes:
- ./backup-container.sh:/usr/local/bin/backup.sh:ro
- ./wp:/source/wp:ro
- ./backups:/backups
environment:
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
- BACKUP_RETENTION_DAYS=${BACKUP_RETENTION_DAYS:-7}
networks:
- backend
networks:
frontend:
backend:
internal: true
volumes:
redis_data:

View File

@@ -4,3 +4,5 @@ MYSQL_USER=wordpress
MYSQL_PASSWORD=$( openssl rand -hex 16 )
WP_PORT=8080
STATIC_PORT=8081
BACKUP_SCHEDULE=0 2 * * *
BACKUP_RETENTION_DAYS=7

2
redis/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore