#!/bin/bash

set -euo pipefail

source /etc/restic/edge01.env

exec 9>/run/restic-edge01.lock

if ! flock -n 9; then
    echo "Another Restic operation is already running."
    exit 1
fi

echo "Starting Restic retention at $(date --iso-8601=seconds)"

restic forget \
    --host edge01 \
    --tag automatic \
    --keep-daily 7 \
    --keep-weekly 4 \
    --keep-monthly 12 \
    --prune

echo "Retention completed at $(date --iso-8601=seconds)"
