restic-compose-backup/README.md

140 lines
2.8 KiB
Markdown
Raw Normal View History

2019-04-13 19:04:54 +02:00
2019-12-03 09:40:02 +01:00
# restic-compose-backup
2019-04-13 19:04:54 +02:00
*WORK IN PROGRESS*
2019-04-17 20:13:23 +02:00
Backup using https://restic.net/ for a docker-compose setup.
2019-04-13 19:04:54 +02:00
2019-12-02 23:12:30 +01:00
Automatically detects and backs up volumes, mysql, mariadb and postgres databases in a docker-compose setup.
2019-04-13 23:12:56 +02:00
This includes both host mapped volumes and actual docker volumes.
2019-04-13 19:04:54 +02:00
2019-12-02 23:12:30 +01:00
* 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
2019-12-03 09:43:21 +01:00
* Volumes are mounted to `/backup/<service_name>/<path>`
2019-12-02 23:12:30 +01:00
in the backup process container. `/backup` is pushed into restic
* Databases are backed up from stdin / dumps
2019-04-13 19:04:54 +02:00
* Cron triggers backup
## Configuration
2019-04-13 23:59:54 +02:00
Required env variables for restic:
2019-04-13 20:12:25 +02:00
```bash
RESTIC_REPOSITORY
RESTIC_PASSWORD
```
2019-04-13 23:59:54 +02:00
Backend specific env vars : https://restic.readthedocs.io/en/stable/040_backup.html#environment-variables
2019-12-02 23:12:30 +01:00
### Volumes
2019-04-13 23:59:54 +02:00
```yaml
version: '3'
services:
2019-12-02 23:12:30 +01:00
# The backup service
2019-04-13 23:59:54 +02:00
backup:
2019-12-03 09:43:21 +01:00
build: restic-compose-backup
2019-04-13 23:59:54 +02:00
environment:
- RESTIC_REPOSITORY=<whatever restic supports>
- RESTIC_PASSWORD=hopefullyasecturepw
env_file:
- some_other_vars.env
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
2019-12-02 23:12:30 +01:00
2019-04-14 00:57:38 +02:00
example:
2019-04-13 23:59:54 +02:00
image: some_image
# Enable volume backup with label
labels:
2019-12-03 09:43:21 +01:00
restic-compose-backup.volumes: true
2019-04-13 23:59:54 +02:00
# These volumes will be backed up
volumes:
2019-04-14 00:02:40 +02:00
# Docker volume
- media:/srv/media
# Host map
- /srv/files:/srv/files
2019-04-13 23:59:54 +02:00
volumes:
media:
2019-04-14 00:57:38 +02:00
```
2019-12-02 23:12:30 +01:00
A simple `include` and `exclude` filter is also available.
2019-04-14 00:57:38 +02:00
```yaml
2019-04-14 00:58:28 +02:00
example:
2019-04-14 00:57:38 +02:00
image: some_image
labels:
2019-12-03 09:43:21 +01:00
restic-compose-backup.volumes: true
restic-compose-backup.volumes.include: "files,data"
2019-04-14 00:57:38 +02:00
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:
```
2019-12-02 23:12:30 +01:00
Exclude
2019-04-14 00:57:38 +02:00
```yaml
2019-04-14 00:58:28 +02:00
example:
2019-04-14 00:57:38 +02:00
image: some_image
labels:
2019-12-03 09:43:21 +01:00
restic-compose-backup.volumes: true
restic-compose-backup.volumes.exclude: "media"
2019-04-14 00:57:38 +02:00
volumes:
# Excluded by filter
- media:/srv/media
# Backed up
- files:/srv/files
- /srv/data:/srv/data
volumes:
media:
files:
```
2019-04-15 16:59:53 +02:00
2019-12-02 23:12:30 +01:00
### 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.
2019-04-15 16:59:53 +02:00
2019-12-02 23:12:30 +01:00
```yaml
mariadb:
image: mariadb:10
labels:
2019-12-03 09:43:21 +01:00
restic-compose-backup.mariadb: true
2019-04-15 16:59:53 +02:00
```
2019-12-02 23:12:30 +01:00
```yaml
mysql:
image: mysql:5
labels:
2019-12-03 09:43:21 +01:00
restic-compose-backup.mysql: true
2019-12-02 23:12:30 +01:00
```
```yaml
postgres:
image: postgres
labels:
2019-12-03 09:43:21 +01:00
restic-compose-backup.postgres: true
2019-04-15 16:59:53 +02:00
```
2019-04-15 19:49:15 +02:00
2019-12-02 23:12:30 +01:00
## Running Tests
2019-04-15 19:49:15 +02:00
```
2019-12-02 23:12:30 +01:00
python setup.py develop
pip install -r tests/requirements.txt
pytest tests
2019-04-15 19:49:15 +02:00
```