This commit is contained in:
parent
4753f6f057
commit
5698b278b5
2 changed files with 87 additions and 1 deletions
83
README.md
83
README.md
|
|
@ -68,10 +68,11 @@ This container automatically detects the database type (MariaDB or PostgreSQL) i
|
||||||
|
|
||||||
### Backup Methods
|
### Backup Methods
|
||||||
|
|
||||||
The container supports two backup methods:
|
The container supports three execution modes:
|
||||||
|
|
||||||
1. **`restic`** - Backup to Restic repositories (cloud storage, remote servers)
|
1. **`restic`** - Backup to Restic repositories (cloud storage, remote servers)
|
||||||
2. **`local`** - Create compressed local backup files
|
2. **`local`** - Create compressed local backup files
|
||||||
|
3. **`loop`** - Keep container running for external schedulers (e.g., Ofelia, Kubernetes CronJob)
|
||||||
|
|
||||||
### Restic Backups
|
### Restic Backups
|
||||||
|
|
||||||
|
|
@ -97,6 +98,18 @@ docker run --rm \
|
||||||
gitea.ceperka.net/rosti/db-backup:latest local
|
gitea.ceperka.net/rosti/db-backup:latest local
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Loop Mode (For External Schedulers)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
-e CONTAINER=my-mariadb-container \
|
||||||
|
-e MARIADB_ROOT_PASSWORD=db-password \
|
||||||
|
gitea.ceperka.net/rosti/db-backup:latest loop
|
||||||
|
```
|
||||||
|
|
||||||
|
In loop mode, the container stays running indefinitely, allowing external schedulers like Ofelia, Kubernetes CronJobs, or other orchestrators to execute the backup scripts directly inside the running container.
|
||||||
|
|
||||||
### With Docker Compose
|
### With Docker Compose
|
||||||
|
|
||||||
#### Restic Backup Setup
|
#### Restic Backup Setup
|
||||||
|
|
@ -163,6 +176,52 @@ volumes:
|
||||||
db_data:
|
db_data:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Loop Mode with External Scheduler (Ofelia)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
database:
|
||||||
|
image: mariadb:latest
|
||||||
|
environment:
|
||||||
|
MARIADB_ROOT_PASSWORD: secretpassword
|
||||||
|
MARIADB_DATABASE: myapp
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/mysql
|
||||||
|
|
||||||
|
backup:
|
||||||
|
image: gitea.ceperka.net/rosti/db-backup:latest
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
environment:
|
||||||
|
CONTAINER: database
|
||||||
|
TARGET_DIR: /backups
|
||||||
|
MARIADB_ROOT_PASSWORD: secretpassword
|
||||||
|
NOTIFY_URL: https://hc-ping.com/your-healthcheck-uuid
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- ./backups:/backups
|
||||||
|
command: ["loop"]
|
||||||
|
labels:
|
||||||
|
ofelia.enabled: "true"
|
||||||
|
ofelia.job-exec.backup-local.schedule: "0 2 * * *"
|
||||||
|
ofelia.job-exec.backup-local.command: "/backup_local.sh"
|
||||||
|
ofelia.job-exec.backup-restic.schedule: "0 3 * * *"
|
||||||
|
ofelia.job-exec.backup-restic.command: "/backup_restic.sh"
|
||||||
|
|
||||||
|
scheduler:
|
||||||
|
image: mcuadros/ofelia:latest
|
||||||
|
depends_on:
|
||||||
|
- backup
|
||||||
|
command: daemon --docker
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
|
```
|
||||||
|
|
||||||
### Scheduled Backups with Cron
|
### Scheduled Backups with Cron
|
||||||
|
|
||||||
To run backups on a schedule, you can use cron or a container orchestrator:
|
To run backups on a schedule, you can use cron or a container orchestrator:
|
||||||
|
|
@ -179,6 +238,28 @@ To run backups on a schedule, you can use cron or a container orchestrator:
|
||||||
0 3 * * * docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /host/backups:/backups -e CONTAINER=my-db -e TARGET_DIR=/backups -e MARIADB_ROOT_PASSWORD=dbpass gitea.ceperka.net/rosti/db-backup:latest local
|
0 3 * * * docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /host/backups:/backups -e CONTAINER=my-db -e TARGET_DIR=/backups -e MARIADB_ROOT_PASSWORD=dbpass gitea.ceperka.net/rosti/db-backup:latest local
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### External Schedulers with Loop Mode
|
||||||
|
|
||||||
|
When using loop mode, you can execute backups from external schedulers by running the backup scripts directly inside the running container:
|
||||||
|
|
||||||
|
#### With Ofelia Scheduler
|
||||||
|
Ofelia can execute jobs in running containers using labels (see Docker Compose example above).
|
||||||
|
|
||||||
|
#### Manual Execution in Loop Mode
|
||||||
|
```bash
|
||||||
|
# Execute local backup in running container
|
||||||
|
docker exec <container-name> /backup_local.sh
|
||||||
|
|
||||||
|
# Execute restic backup in running container
|
||||||
|
docker exec <container-name> /backup_restic.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
#### With Kubernetes CronJob + Running Pod
|
||||||
|
```bash
|
||||||
|
# Execute backup in running pod
|
||||||
|
kubectl exec <pod-name> -- /backup_local.sh
|
||||||
|
```
|
||||||
|
|
||||||
### Kubernetes CronJob
|
### Kubernetes CronJob
|
||||||
|
|
||||||
#### Restic Backup CronJob
|
#### Restic Backup CronJob
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@ if [ "$1" = "local" ]; then
|
||||||
source /backup_local.sh
|
source /backup_local.sh
|
||||||
elif [ "$1" = "restic" ]; then
|
elif [ "$1" = "restic" ]; then
|
||||||
source /backup_restic.sh
|
source /backup_restic.sh
|
||||||
|
elif [ "$1" = "loop" ]; then
|
||||||
|
# Inifinite loop to keep the container running and let Ofelia scheduler (or any other) manage the execution
|
||||||
|
while true; do
|
||||||
|
sleep 86400
|
||||||
|
done
|
||||||
else
|
else
|
||||||
echo "Unknown backup method. Use 'local' or 'restic'."
|
echo "Unknown backup method. Use 'local' or 'restic'."
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue