#!/bin/bash
# Retention + prune for the azkaban restic repo. Separate from the backup job
# because prune is far more API- and CPU-expensive than backing up ~50 MB.
set -euo pipefail

source /root/.restic-env
export HOME=/root

# The daily backup (restic-backup.service, ~100 min when vzdump images changed)
# holds a repo lock and can still be running at the Sunday 04:45-05:15 prune
# slot: wait for it instead of failing (2026-11-15: exit 11, lock 2m46s old).
exec restic \
    --password-file /root/.resticpwd \
    --retry-lock "${CTG_RETRY_LOCK:-3h}" \
    forget \
    --group-by host \
    --keep-within 30d \
    --prune
