kopia_backup: render per-source retention overrides from kopia_backup.retention

This commit is contained in:
2026-11-01 09:07:04 +00:00
parent ca34bd8363
commit add568a242
+18
View File
@@ -50,6 +50,24 @@ ignore() {
ignore {{ i.key | quote }} {{ i.value | map('quote') | join(' ') }} ignore {{ i.key | quote }} {{ i.value | map('quote') | join(' ') }}
{% endfor %} {% endfor %}
{% endif %} {% 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 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") [ -d "$p" ] && sources+=("$p")