Go to file
kolaente 5acf40d86e
All checks were successful
continuous-integration/drone/push Build is passing
feat: add backup compression
2024-02-13 16:45:16 +01:00
.drone.yml feat: add drone config 2021-12-11 12:54:34 +01:00
.gitignore feat: add backup compression 2024-02-13 16:45:16 +01:00
cleanup.go feat: cleanup old backups 2021-12-05 13:38:36 +01:00
client.go Add methods to get containers 2021-08-18 20:09:45 +02:00
config.go feat: add backup compression 2024-02-13 16:45:16 +01:00
Dockerfile fix: add ca root certificates 2023-06-05 19:07:15 +02:00
dump_mysql_test.go fix: make mysql backups work 2023-07-03 22:46:38 +02:00
dump_mysql.go feat: add backup compression 2024-02-13 16:45:16 +01:00
dump_postgres.go feat: add backup compression 2024-02-13 16:45:16 +01:00
dump_test.go Add test for determining the container dumper type 2021-08-18 22:38:59 +02:00
dump.go fix: wrong import 2023-06-15 14:35:28 +02:00
go.mod feat: add backup compression 2024-02-13 16:45:16 +01:00
go.sum feat: replace interval with a proper cron schedule 2021-12-30 12:57:58 +01:00
helper.go fix: don't crash when encountering a container with empty env variables 2023-11-15 12:05:29 +01:00
LICENSE chore: add license 2021-12-05 13:49:06 +01:00
main.go feat: add BACKUP_NO_CRON config to allow running the backup without cron schedule 2024-02-13 16:41:27 +01:00
README.md feat: add backup compression 2024-02-13 16:45:16 +01:00
save.go feat: add backup compression 2024-02-13 16:45:16 +01:00
store.go feat: remove old containers 2021-12-05 13:40:53 +01:00
webhook.go feat: add completion webhook url 2023-06-05 18:35:21 +02:00

Zero-Fuss Docker Database Backup

Build Status

A simple tool to create backup of all databases on a host. Supports postgres and mysql/mariadb.

Successor to this script.


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

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 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.

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


All config is done with environment variables.


Where all backup files will be stored.

Default: /backups


The cron schedule at which the backup job runs, using the common unix cron syntax.

Check out crontab.dev for a nice explanation of the schedule.

Default: 0 */6 * * * (every 6 hours)


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


How many backups to keep. If more backups are stored in the backup folder, the oldest one will be removed until there are only as many as this config variable.

Default: 12


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.


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.