Go to file
kolaente 064d2ce66e
continuous-integration/drone/push Build is passing Details
feat: change the backup date format to make sure the backups sort properly
2022-01-08 12:33:54 +01:00
.drone.yml feat: add drone config 2021-12-11 12:54:34 +01:00
.gitignore Add postgres dumper 2021-08-18 21:50:04 +02:00
Dockerfile feat: scratch docker image 2021-12-05 12:44:47 +01:00
LICENSE chore: add license 2021-12-05 13:49:06 +01:00
README.md docs: fix backups volume mount in example 2022-01-08 12:23:21 +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: change the backup date format to make sure the backups sort properly 2022-01-08 12:33:54 +01:00
dump.go fix: find db images with all kinds of tags 2021-12-05 13:54:39 +01:00
dump_mysql.go chore: use log everywhere 2021-12-05 13:44:36 +01:00
dump_mysql_test.go Add tests to build mysql args 2021-08-18 22:34:28 +02:00
dump_postgres.go chore: use log everywhere 2021-12-05 13:44:36 +01:00
dump_postgres_test.go feat: move running the actual dump command to the db container 2021-12-05 12:39:23 +01:00
dump_test.go Add test for determining the container dumper type 2021-08-18 22:38:59 +02:00
go.mod feat: replace interval with a proper cron schedule 2021-12-30 12:57:58 +01:00
go.sum feat: replace interval with a proper cron schedule 2021-12-30 12:57:58 +01:00
helper.go Add dump helpers 2021-08-18 21:29:17 +02:00
main.go fix: cron not running in foreground 2022-01-06 13:05:09 +01:00
save.go feat: restructure writing to the file 2021-12-05 13:24:06 +01:00
store.go feat: remove old containers 2021-12-05 13:40:53 +01:00

README.md

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.

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

The tool will find all database containers 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).

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'
services:
  backup:
    image: kolaente/db-backup
    restart: unless-stopped
    volumes:
      - ./backups:/backups
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock

Config

All config is done with environment variables.

BACKUP_FOLDER

Where all backup files will be stored.

Default: /backups

BACKUP_SCHEDULE

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)

BACKUP_MAX

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

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.