Go to file
Einar Forselv 36231da47f Update README.md 2019-12-02 23:12:30 +01:00
restic_volume_backup Separate mariadb and mysql 2019-12-02 22:53:00 +01:00
tests tests: volumes_for_backup 2019-11-26 14:24:42 +01:00
.dockerignore Cleanup 2019-11-15 14:23:56 +01:00
.gitignore Update .gitignore 2019-11-26 21:45:57 +01:00
Dockerfile Bump to restic 9.6 2019-12-02 21:14:57 +01:00
README.md Update README.md 2019-12-02 23:12:30 +01:00
crontab Cleanup 2019-11-15 14:23:56 +01:00
docker-compose.yaml Separate mariadb and mysql 2019-12-02 22:53:00 +01:00
entrypoint.sh Cleanup 2019-11-15 14:23:56 +01:00
pytest.ini Basic testcase setup 2019-04-15 19:07:14 +02:00
restic_volume_backup.env Write restic db to local fs 2019-11-26 20:00:54 +01:00
setup.py Add rvb command shortcut 2019-11-12 12:09:59 +01:00

README.md

restic-volume-backup

WORK IN PROGRESS

Backup using https://restic.net/ for a docker-compose setup.

Automatically detects and backs up volumes, mysql, mariadb and postgres databases in a docker-compose setup. This includes both host mapped volumes and actual docker volumes.

  • Each service in the compose setup is configured with a label to enable backup of volumes or databases
  • When backup starts a new instance of the container is created mapping in all the needed volumes. It will copy networks etc to ensure databases can be reached
  • Volumes are mounter to /backup/<service_name>/<path> in the backup process container. /backup is pushed into restic
  • Databases are backed up from stdin / dumps
  • Cron triggers backup

Configuration

Required env variables for restic:

RESTIC_REPOSITORY
RESTIC_PASSWORD

Backend specific env vars : https://restic.readthedocs.io/en/stable/040_backup.html#environment-variables

Volumes

version: '3'
services:
  # The backup service
  backup:
    build: restic-volume-backup
    environment:
      - RESTIC_REPOSITORY=<whatever restic supports>
      - RESTIC_PASSWORD=hopefullyasecturepw
    env_file:
      - some_other_vars.env
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

  example:
    image: some_image
    # Enable volume backup with label
    labels:
      restic-volume-backup.enabled: true
    # These volumes will be backed up
    volumes:
      # Docker volume
      - media:/srv/media
      # Host map
      - /srv/files:/srv/files

volumes:
  media:

A simple include and exclude filter is also available.

  example:
    image: some_image
    labels:
      restic-volume-backup.enabled: true
      restic-volume-backup.include: "files,data"
    volumes:
      # Source don't match include filter. No backup.
      - media:/srv/media
      # Matches include filter
      - files:/srv/files
      - /srv/data:/srv/data

volumes:
  media:
  files:

Exclude

  example:
    image: some_image
    labels:
      restic-volume-backup.enabled: true
      restic-volume-backup.exclude: "media"
    volumes:
      # Excluded by filter
      - media:/srv/media
      # Backed up
      - files:/srv/files
      - /srv/data:/srv/data

volumes:
  media:
  files:

Databases

Will dump databases directly into restic through stdin. They will appear in restic as a separate snapshot with path /backup/<service_name>/dump.sql or similar.

  mariadb:
    image: mariadb:10
    labels:
      restic-volume-backup.mariadb: true
  mysql:
    image: mysql:5
    labels:
      restic-volume-backup.mysql: true
  postgres:
    image: postgres
    labels:
      restic-volume-backup.postgres: true

Running Tests

python setup.py develop
pip install -r tests/requirements.txt
pytest tests