From 231c9832053c3f53df8c5d8e49c8d3951e3e48c7 Mon Sep 17 00:00:00 2001
From: nd <git@notandy.de>
Date: Thu, 2 Dec 2021 22:54:14 +0100
Subject: [PATCH] add support for custom restic flags

---
 defaults/main.yml              | 2 ++
 tasks/main.yml                 | 2 +-
 templates/backup-check.j2      | 2 +-
 templates/backup-retention.j2  | 2 +-
 templates/backup-standalone.j2 | 2 +-
 templates/backup-vm.j2         | 2 +-
 6 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/defaults/main.yml b/defaults/main.yml
index 77ee36e..f8db1ff 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -18,6 +18,8 @@ backups:
       repo_type: local
       repo_folder_create: true
       additional_keys: {}
+      flags:
+        - "--cleanup-cache"
   mode: vm-via-hypervisor
   enabled: True
   retention:
diff --git a/tasks/main.yml b/tasks/main.yml
index 2ac9ec5..f3cfd15 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -2,7 +2,7 @@
   set_fact:
     backup_backend: "{% if backups.mode in ['standalone-restic', 'hypervisor-restic'] %}restic{% else %}False{% endif %}"
     backup_executor: "{% if backups.mode in ['vm-via-hypervisor'] %}False{% else %}True{% endif %}"
-    backup_restic_cache: "{% if backups.backends.restic.repo_type == 'local' %}False{% else %}True{% endif %}"
+    restic_combined_flags: "{{ (backups.backends.restic.flags + (['--no-cache'] if backups.backends.restic.repo_type == 'local' else []))| join(' ') }}"
 
 - name: create config folder
   file:
diff --git a/templates/backup-check.j2 b/templates/backup-check.j2
index 67f73bb..843a0c5 100755
--- a/templates/backup-check.j2
+++ b/templates/backup-check.j2
@@ -6,7 +6,7 @@ set -euo pipefail
 source /etc/backup-client/restic.env
 
 restic check --read-data \
-	--cleanup-cache{% if not backup_restic_cache %} --no-cache{% endif %}
+	{{ restic_combined_flags }}
 
 {% endif %}
 
diff --git a/templates/backup-retention.j2 b/templates/backup-retention.j2
index 3778e51..741029d 100755
--- a/templates/backup-retention.j2
+++ b/templates/backup-retention.j2
@@ -7,7 +7,7 @@ source /etc/backup-client/retention.env
 # restic backend
 source /etc/backup-client/restic.env
 restic forget \
-	--cleanup-cache {% if not backup_restic_cache %} --no-cache{% endif %} \
+	{{ restic_combined_flags }} \
 	--verbose \
 	--prune \
 	--group-by "host,paths,tags" \
diff --git a/templates/backup-standalone.j2 b/templates/backup-standalone.j2
index 20d1f43..bd5dd65 100755
--- a/templates/backup-standalone.j2
+++ b/templates/backup-standalone.j2
@@ -8,7 +8,7 @@ test -f "/etc/backup-client/enabled" || { echo "Standalone backup is disabled";
 source /etc/backup-client/restic.env
 
 restic backup \
-	--cleanup-cache {% if not backup_restic_cache %} --no-cache{% endif %} \
+	{{ restic_combined_flags }} \
 	--verbose \
 	--exclude-caches \
 	--one-file-system \
diff --git a/templates/backup-vm.j2 b/templates/backup-vm.j2
index 9c6ed30..79438f3 100755
--- a/templates/backup-vm.j2
+++ b/templates/backup-vm.j2
@@ -122,7 +122,7 @@ set -euo pipefail
 		# restic backend
 		source /etc/backup-client/restic.env
 		restic backup \
-			--cleanup-cache {% if not backup_restic_cache %} --no-cache{% endif %} \
+			{{ restic_combined_flags }} \
 			--verbose \
 			--host "$DOMAIN" \
 			--exclude-file "/etc/backup-client/vms/$DOMAIN/exclude_files" \
-- 
GitLab