96 lines
2.8 KiB
Raw Permalink Normal View History

2021-08-18 20:05:17 +00:00
# Zero-Fuss Docker Database Backup
2021-08-18 20:05:02 +00:00
2021-12-11 11:54:34 +00:00
[![Build Status](](
2021-08-18 20:05:02 +00:00
A simple tool to create backup of all databases on a host. Supports postgres and mysql/mariadb.
Successor to [this script](
## Usage
Simply point it at your docker socket, mount a backup volume and be done:
docker run -v $PWD/backups:/backups -v /var/run/docker.sock:/var/run/docker.sock kolaente/db-backup
2021-08-18 20:05:02 +00:00
The tool will find all database containers running an official [`mysql`](,
[`mariadb`]( or [`postgres`]( image and
create backups of them periodically. It will also discover new containers
2021-08-18 20:05:02 +00:00
as they are started and won't try to back up containers which have gone away.
When running, all backups for the current run are time-stamped into a sub folder of the backup directory (see below).
### Using labels
To make the backup tool discover other non-offical containers as well you can add the label `de.kolaente.db-backup` to
any container with a value of `mysql` or `postgres` to treat it as a mysql or postgres container.
2021-12-30 11:38:54 +00:00
### Docker Compose
If you're running docker-compose, you can use a setup similar to the following compose file to run the backup:
version: '2'
image: kolaente/db-backup
restart: unless-stopped
- ./backups:/backups
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock
2021-08-18 20:05:02 +00:00
## Config
All config is done with environment variables.
Where all backup files will be stored.
Default: `/backups`
2021-08-18 20:05:02 +00:00
The cron schedule at which the backup job runs, using the common unix cron syntax.
2021-08-18 20:05:02 +00:00
Check out []( for a nice explanation of the schedule.
2022-01-06 12:04:53 +00:00
Default: `0 */6 * * *` (every 6 hours)
2021-08-18 20:05:02 +00:00
If provided, runs the backup only once without a cron schedule. This is useful for one-off backups of testing if the configuration works.
Default: `false`
2021-08-18 20:05:02 +00:00
How many backups to keep. If more backups are stored in the backup folder, the oldest one will be removed until there
2021-12-05 10:31:38 +00:00
are only as many as this config variable.
2021-08-18 20:05:02 +00:00
2021-12-05 12:45:42 +00:00
Default: `12`
2023-06-05 16:35:21 +00:00
If provided, the tool will do an empty GET request to this URL to indicate it successfully completed the backup job.
You can use this with other tools to monitor if backups are completed as they should.
2024-02-13 15:45:10 +00:00
If set provided and set to `true`, all backups will be compressed using gzip.
## Building from source
This project uses go modules, so you'll need at least go 1.11 to compile it.
Simply run
go build .
to build the binary.