From c4c8d6de7f83714781164cd0e5b134f9babed517 Mon Sep 17 00:00:00 2001 From: alessandrovitali Date: Thu, 9 Jul 2026 16:42:10 +0200 Subject: [PATCH] feat: make backup role universal by passing paths as variables --- roles/backup/defaults/main.yml | 14 ++++++++++++++ roles/backup/templates/restic-backup.sh.j2 | 17 ++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 roles/backup/defaults/main.yml diff --git a/roles/backup/defaults/main.yml b/roles/backup/defaults/main.yml new file mode 100644 index 0000000..25bf917 --- /dev/null +++ b/roles/backup/defaults/main.yml @@ -0,0 +1,14 @@ +# ansible/roles/backup/defaults/main.yml +--- +## Directories to include in the backup +backup_include_paths: + - /etc + - /opt/docker + +## Directories to exclude from the backup +backup_exclude_paths: [] ## Nothing to exclude + +## Restic retention policy +backup_retention_daily: 7 +backup_retention_weekly: 4 +backup_retention_monthly: 6 diff --git a/roles/backup/templates/restic-backup.sh.j2 b/roles/backup/templates/restic-backup.sh.j2 index 1f33c22..8921f25 100644 --- a/roles/backup/templates/restic-backup.sh.j2 +++ b/roles/backup/templates/restic-backup.sh.j2 @@ -11,13 +11,20 @@ set -e echo "Starting Restic Backup at $(date)" -## Run the backup (docker volumes & config files) +## Run the backup using paths and exclusions defined in group_vars restic backup \ - /etc \ - /opt/docker-data \ - --exclude /opt/docker-data/tmp \ +{% for path in backup_include_paths %} + "{{ path }}" \ +{% endfor %} +{% for path in backup_exclude_paths %} + --exclude "{{ path }}" \ +{% endfor %} --cleanup-cache -restic forget --prune --keep-daily 7 --keep-weekly 4 --keep-monthly 6 +restic forget \ + --prune \ + --keep-daily {{ backup_retention_daily }} \ + --keep-weekly {{ backup_retention_weekly }} \ + --keep-monthly {{ backup_retention_monthly }} echo "Restic backup completed at $(date)"