ZettaIO / restic-compose-backup

Automatic restic backup of a docker-compose setup. https://hub.docker.com/r/zettaio/restic-compose-backup
MIT License
29 stars 16 forks source link

Allow grouping of backup directories by project name #26

Closed jannikw closed 4 years ago

jannikw commented 4 years ago

When running multiple projects simultaneously where each contains a service with the same name, backups for these services will be merged into one directory. For example take the docker-compose.yml from below, copy it to different directories named project1and project2. Now call docker-compose up -d from each directory and trigger a backup. Backups for both services will be saved in the same subdirectory of /volumes/... since the service names are the same.

version: '3.7'
services:
  web:
    image: nginx
    labels:
      restic-compose-backup.volumes: true
    volumes:
      - ./foo:/srv/foo
      - ./bar:/srv/bar

The same thing applies to databases, just that they are saved in /databases/...

Therefore I propose a new configuration flag set via the environment variable INCLUDE_PROJECT_NAME. If the flag is set to false (which it is per default) then the old behavior for the backup destination is chosen. If the flag is set to true, the volume backups will be placed at /volumes/<project name>/<service name>/... and the database backups at /databases/<project name>/<service name>/....

In order to make viewing the destination paths of the backups a little easier I also extended the output of the status command to include the destination paths. The output now looks like this for the test compose file:

2020-05-26 12:47:32,710 - INFO: Status for compose project 'restic-compose-backup'
2020-05-26 12:47:32,710 - INFO: Repository: '/restic_data'
2020-05-26 12:47:32,710 - INFO: Backup currently running?: False
2020-05-26 12:47:32,710 - INFO: Include project name in backup path?: False
2020-05-26 12:47:32,710 - INFO: Checking docker availability
2020-05-26 12:47:33,474 - INFO: ------------------------- Detected Config -------------------------
2020-05-26 12:47:33,475 - INFO: service: postgres
2020-05-26 12:47:33,502 - INFO:  - postgres (is_ready=True) -> /databases/postgres/test.sql
2020-05-26 12:47:33,503 - INFO: service: web
2020-05-26 12:47:33,504 - INFO:  - volume: /home/jannik/development/restic-compose-backup/src/tests -> /volumes/web/srv/tests
2020-05-26 12:47:33,504 - INFO: service: mariadb
2020-05-26 12:47:33,533 - INFO:  - mariadb (is_ready=True) -> /databases/mariadb/all_databases.sql
2020-05-26 12:47:33,533 - INFO: service: mysql
2020-05-26 12:47:33,543 - INFO:  - mysql (is_ready=True) -> /databases/mysql/all_databases.sql
2020-05-26 12:47:33,544 - INFO: -------------------------------------------------------------------
jannikw commented 4 years ago

Another good name for the flag could be GROUP_BACKUPS_BY_PROJECT_NAME.

einarf commented 4 years ago

Looks reasonable. I actually think I had something like this initially but somehow decided to simplify it. I think also GROUP_BACKUPS_BY_PROJECT_NAME might be better, but I'll merge this now and modify if needed.