From add568a2424c5670f46c7b85c8bf34ee84a5841c Mon Sep 17 00:00:00 2001 From: Ruakij Date: Sun, 1 Nov 2026 09:07:04 +0000 Subject: [PATCH] kopia_backup: render per-source retention overrides from kopia_backup.retention --- kopia_backup/templates/kopia-backup.j2 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kopia_backup/templates/kopia-backup.j2 b/kopia_backup/templates/kopia-backup.j2 index 90787aa..c71c73f 100644 --- a/kopia_backup/templates/kopia-backup.j2 +++ b/kopia_backup/templates/kopia-backup.j2 @@ -50,6 +50,24 @@ ignore() { ignore {{ i.key | quote }} {{ i.value | map('quote') | join(' ') }} {% endfor %} {% endif %} +{% set retentions = kopia_backup.retention | default({}) | dict2items | rejectattr('value', 'none') | list %} +{% if retentions %} + +# Per-source retention overrides, applied as a whole (--clear-retention runs after the keep flags within one call). +retention() { + local path=$1; shift + kopia policy set "$path" --clear-retention >/dev/null 2>&1 && + kopia policy set "$path" "$@" >/dev/null 2>&1 || + { echo "setting the retention of $path failed" >&2; failed=1; } +} +{% for r in retentions %} +retention {{ r.key | quote }} \ + --keep-daily={{ r.value.keep_daily | default(0) }} \ + --keep-weekly={{ r.value.keep_weekly | default(0) }} \ + --keep-monthly={{ r.value.keep_monthly | default(0) }} \ + --keep-annual={{ r.value.keep_annual | default(0) }} +{% endfor %} +{% endif %} for p in {{ kopia_backup.sources | map('quote') | join(' ') }}{{ ' "$etcd"' if kopia_backup.etcd_snapshot }}{{ ' "$dumps"' if kopia_backup.dumps }}; do [ -d "$p" ] && sources+=("$p")