#!/bin/sh
set -eu

# Prune mc-proxy database backups older than RETAIN_DAYS (default 30).
BACKUP_DIR="/srv/mc-proxy/backups"
RETAIN_DAYS="${1:-30}"

if [ ! -d "${BACKUP_DIR}" ]; then
    echo "Backup directory ${BACKUP_DIR} does not exist."
    exit 0
fi

find "${BACKUP_DIR}" -name "mc-proxy-*.db" -type f -mtime "+${RETAIN_DAYS}" -delete
echo "Pruned backups older than ${RETAIN_DAYS} days from ${BACKUP_DIR}."
