#!/bin/sh # Prune old backup files according to retention policy. # daily: keep 14 weekly: keep 8 monthly: keep 6 set -eu prune() { local dir="$1" local keep="$2" [ -d "$dir" ] || return 0 # Files are YYYY-MM-DD.dump; lexicographic sort = chronological. # tail skips the N newest; xargs deletes the rest. ls -1 "$dir"/*.dump 2>/dev/null \ | sort \ | head -n "-$keep" \ | xargs -r rm -f -- } for db in famapp authentik; do prune "/backups/$db/daily" 14 prune "/backups/$db/weekly" 8 prune "/backups/$db/monthly" 6 done echo "[retain] done"