2019-04-13 17:04:54 +00:00
|
|
|
|
2019-12-03 08:40:02 +00:00
|
|
|
# restic-compose-backup
|
2019-04-13 17:04:54 +00:00
|
|
|
|
2019-12-05 01:31:20 +00:00
|
|
|
![docs](https://readthedocs.org/projects/restic-compose-backup/badge/?version=latest)
|
|
|
|
|
2019-12-08 13:57:17 +00:00
|
|
|
Backup using [restic] for a docker-compose setup.
|
2019-12-08 14:13:06 +00:00
|
|
|
Currently tested with docker-ce 17, 18 and 19.
|
2019-04-13 17:04:54 +00:00
|
|
|
|
2019-12-05 00:58:50 +00:00
|
|
|
* [restic-compose-backup Documentation](https://restic-compose-backup.readthedocs.io)
|
|
|
|
* [restic-compose-backup on Github](https://github.com/ZettaIO/restic-compose-backup)
|
|
|
|
* [restic-compose-backup on Docker Hub](https://hub.docker.com/r/zettaio/restic-compose-backup)
|
|
|
|
|
|
|
|
Features:
|
|
|
|
|
2019-12-07 08:15:34 +00:00
|
|
|
* Backs up docker volumes or host binds
|
2019-12-08 13:57:17 +00:00
|
|
|
* Backs up postgres, mariadb and mysql databases
|
|
|
|
* Notifications over mail/smtp or Discord webhooks
|
2019-12-05 00:58:50 +00:00
|
|
|
|
|
|
|
Please report issus on [github](https://github.com/ZettaIO/restic-compose-backup/issues).
|
2019-12-03 23:36:28 +00:00
|
|
|
|
2019-12-03 09:19:12 +00:00
|
|
|
## Install
|
|
|
|
|
|
|
|
```bash
|
|
|
|
docker pull zettaio/restic-compose-backup
|
|
|
|
```
|
|
|
|
|
2019-12-08 13:57:17 +00:00
|
|
|
## Configuration (env vars)
|
2019-04-13 17:04:54 +00:00
|
|
|
|
2019-12-08 14:10:06 +00:00
|
|
|
Minimum configuration
|
2019-04-13 21:59:54 +00:00
|
|
|
|
2019-04-13 18:12:25 +00:00
|
|
|
```bash
|
|
|
|
RESTIC_REPOSITORY
|
|
|
|
RESTIC_PASSWORD
|
|
|
|
```
|
2019-04-13 21:59:54 +00:00
|
|
|
|
2019-12-08 13:57:17 +00:00
|
|
|
More config options can be found in the [documentation].
|
2019-04-13 23:40:42 +00:00
|
|
|
|
2019-12-08 13:57:17 +00:00
|
|
|
Restic backend specific env vars : https://restic.readthedocs.io/en/stable/040_backup.html#environment-variables
|
2019-12-05 00:58:50 +00:00
|
|
|
|
2019-12-08 14:10:06 +00:00
|
|
|
## Compose Example
|
|
|
|
|
|
|
|
We simply control what should be backed up by adding
|
|
|
|
labels to our containers. More details are covered
|
|
|
|
in the [documentation].
|
2019-12-08 13:57:17 +00:00
|
|
|
|
|
|
|
restic-backup.env
|
|
|
|
|
2019-12-08 14:13:06 +00:00
|
|
|
```bash
|
2019-12-08 13:57:17 +00:00
|
|
|
RESTIC_REPOSITORY=<whatever backend restic supports>
|
|
|
|
RESTIC_PASSWORD=hopefullyasecturepw
|
|
|
|
# snapshot prune rules
|
2019-12-05 00:58:50 +00:00
|
|
|
RESTIC_KEEP_DAILY=7
|
|
|
|
RESTIC_KEEP_WEEKLY=4
|
|
|
|
RESTIC_KEEP_MONTHLY=12
|
|
|
|
RESTIC_KEEP_YEARLY=3
|
2019-12-08 13:57:17 +00:00
|
|
|
# Cron schedule. Run every day at 1am
|
|
|
|
CRON_SCHEDULE="0 1 * * *"
|
2019-12-05 00:58:50 +00:00
|
|
|
```
|
|
|
|
|
2019-12-08 13:57:17 +00:00
|
|
|
docker-compose.yaml
|
2019-04-13 21:59:54 +00:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
version: '3'
|
|
|
|
services:
|
2019-12-02 22:12:30 +00:00
|
|
|
# The backup service
|
2019-04-13 21:59:54 +00:00
|
|
|
backup:
|
2019-12-08 13:57:17 +00:00
|
|
|
image: zettaio/restic-compose-backup:<version>
|
2019-04-13 21:59:54 +00:00
|
|
|
env_file:
|
2019-12-08 13:57:17 +00:00
|
|
|
- restic-backup.env
|
2019-04-13 21:59:54 +00:00
|
|
|
volumes:
|
2019-12-08 13:57:17 +00:00
|
|
|
# We need to communicate with docker
|
2019-04-13 21:59:54 +00:00
|
|
|
- /var/run/docker.sock:/tmp/docker.sock:ro
|
2019-12-08 13:57:17 +00:00
|
|
|
# Persistent storage of restic cache (greatly speeds up all restic operations)
|
|
|
|
- cache:/cache
|
2019-12-08 14:10:06 +00:00
|
|
|
web:
|
2019-04-13 21:59:54 +00:00
|
|
|
image: some_image
|
|
|
|
labels:
|
2019-12-08 13:57:17 +00:00
|
|
|
# Enables backup of the volumes below
|
2019-12-03 08:43:21 +00:00
|
|
|
restic-compose-backup.volumes: true
|
2019-04-13 21:59:54 +00:00
|
|
|
volumes:
|
2019-04-13 22:02:40 +00:00
|
|
|
- media:/srv/media
|
|
|
|
- /srv/files:/srv/files
|
2019-12-02 22:12:30 +00:00
|
|
|
mariadb:
|
|
|
|
image: mariadb:10
|
|
|
|
labels:
|
2019-12-08 13:57:17 +00:00
|
|
|
# Enables backup of this database
|
2019-12-03 08:43:21 +00:00
|
|
|
restic-compose-backup.mariadb: true
|
2019-12-08 13:57:17 +00:00
|
|
|
env_file:
|
|
|
|
mariadb-credentials.env
|
|
|
|
volumes:
|
|
|
|
- mysqldata:/var/lib/mysql
|
2019-12-02 22:12:30 +00:00
|
|
|
mysql:
|
|
|
|
image: mysql:5
|
|
|
|
labels:
|
2019-12-08 13:57:17 +00:00
|
|
|
# Enables backup of this database
|
2019-12-03 08:43:21 +00:00
|
|
|
restic-compose-backup.mysql: true
|
2019-12-08 13:57:17 +00:00
|
|
|
env_file:
|
|
|
|
mysql-credentials.env
|
|
|
|
volumes:
|
|
|
|
- mysqldata:/var/lib/mysql
|
2019-12-02 22:12:30 +00:00
|
|
|
|
|
|
|
postgres:
|
|
|
|
image: postgres
|
|
|
|
labels:
|
2019-12-08 13:57:17 +00:00
|
|
|
# Enables backup of this database
|
2019-12-03 08:43:21 +00:00
|
|
|
restic-compose-backup.postgres: true
|
2019-12-08 13:57:17 +00:00
|
|
|
env_file:
|
|
|
|
postgres-credentials.env
|
|
|
|
volumes:
|
|
|
|
- pgdata:/var/lib/postgresql/data
|
|
|
|
|
|
|
|
volumes:
|
|
|
|
media:
|
|
|
|
mysqldata:
|
|
|
|
mariadbdata:
|
|
|
|
pgdata:
|
|
|
|
cache:
|
2019-04-15 14:59:53 +00:00
|
|
|
```
|
2019-04-15 17:49:15 +00:00
|
|
|
|
2019-12-08 14:10:06 +00:00
|
|
|
## The `rcb` command
|
|
|
|
|
|
|
|
Everything is controlled using the `rcb` command.
|
|
|
|
After configuring backup with labels and restarted
|
|
|
|
the affected services we can quickly view the
|
|
|
|
result using the `status` subcommand.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker-compose run --rm backup rcb status
|
|
|
|
INFO: Status for compose project 'myproject'
|
|
|
|
INFO: Repository: '<restic repository>'
|
|
|
|
INFO: Backup currently running?: False
|
|
|
|
INFO: --------------- Detected Config ---------------
|
|
|
|
INFO: service: mysql
|
|
|
|
INFO: - mysql (is_ready=True)
|
|
|
|
INFO: service: mariadb
|
|
|
|
INFO: - mariadb (is_ready=True)
|
|
|
|
INFO: service: postgres
|
|
|
|
INFO: - postgres (is_ready=True)
|
|
|
|
INFO: service: web
|
|
|
|
INFO: - volume: media
|
|
|
|
INFO: - volume: /srv/files
|
|
|
|
```
|
|
|
|
|
|
|
|
The `status` subcommand lists what will be backed up and
|
|
|
|
even pings the database services checking their availability.
|
|
|
|
The `restic` command can also be used directly in the container.
|
|
|
|
|
|
|
|
More `rcb` commands can be found in the [documentation].
|
|
|
|
|
2019-12-02 22:12:30 +00:00
|
|
|
## Running Tests
|
2019-04-15 17:49:15 +00:00
|
|
|
|
2019-12-05 00:58:50 +00:00
|
|
|
```bash
|
2019-12-07 08:12:01 +00:00
|
|
|
pip install -e ./src/
|
2019-12-05 10:23:33 +00:00
|
|
|
pip install -r src/tests/requirements.txt
|
|
|
|
tox
|
2019-04-15 17:49:15 +00:00
|
|
|
```
|
2019-12-05 00:58:50 +00:00
|
|
|
|
|
|
|
## Building Docs
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pip install -r docs/requirements.txt
|
2019-12-05 10:26:11 +00:00
|
|
|
python src/setup.py build_sphinx
|
2019-12-05 00:58:50 +00:00
|
|
|
```
|
|
|
|
|
2020-03-07 01:24:22 +00:00
|
|
|
# Local dev setup
|
|
|
|
|
|
|
|
The git repository contains a simple local setup for development
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Create an overlay network to link the compose project and stack
|
|
|
|
docker network create --driver overlay --attachable global
|
|
|
|
# Start the compose project
|
|
|
|
docker-compose up -d
|
|
|
|
# Deploy the stack
|
|
|
|
docker stack deploy -c swarm-stack.yml test
|
|
|
|
```
|
|
|
|
|
|
|
|
In dev we should ideally start the backup container manually
|
|
|
|
```bash
|
|
|
|
docker-compose run --rm backup sh
|
|
|
|
# pip install the package in the container in editable mode to auto sync changes from host source
|
|
|
|
pip install -e .
|
|
|
|
```
|
|
|
|
|
2019-12-05 00:58:50 +00:00
|
|
|
## Contributing
|
|
|
|
|
2019-12-05 11:33:24 +00:00
|
|
|
Contributions are welcome regardless of experience level. Don't hesitate submitting issues, opening partial or completed pull requests.
|
2019-12-08 13:57:17 +00:00
|
|
|
|
|
|
|
[restic]: https://restic.net/
|
2019-12-09 03:31:44 +00:00
|
|
|
[documentation]: https://restic-compose-backup.readthedocs.io
|
2019-12-11 12:17:32 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
This project is sponsored by [zetta.io](https://www.zetta.io)
|
|
|
|
|
|
|
|
[![Zetta.IO](https://raw.githubusercontent.com/ZettaIO/restic-compose-backup/master/.github/logo.png)](https://www.zetta.io)
|