Files
proxmox/scripts/maintenance/prune-e2e-verification-evidence.sh
defiQUG 2d4b35c3ee docs(stage4): archive deployment-reports README + E2E evidence hygiene
- deployment-reports: historical notice + SOT links (no per-file edits)
- archive README: link deployment-reports folder
- E2E_ENDPOINTS_LIST: evidence retention + prune script pointer
- prune-e2e-verification-evidence.sh: dry-run default, --apply + KEEP_DAYS

Made-with: Cursor
2026-03-27 16:41:49 -07:00

63 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# List or remove old E2E report dirs under docs/04-configuration/verification-evidence/e2e-verification-*
# Default: dry-run only. Deletes dirs older than KEEP_DAYS (default 45). Never deletes the two latest by mtime.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
EVIDENCE="$PROJECT_ROOT/docs/04-configuration/verification-evidence"
DRY_RUN=true
for a in "$@"; do
[[ "$a" == "--apply" ]] && DRY_RUN=false
done
KEEP_DAYS="${KEEP_DAYS:-45}"
MIN_KEEP="${MIN_KEEP:-2}"
if [[ ! -d "$EVIDENCE" ]]; then
echo "No directory: $EVIDENCE"
exit 1
fi
mapfile -t ALL < <(find "$EVIDENCE" -maxdepth 1 -type d -name 'e2e-verification-*' -printf '%T@ %p\n' 2>/dev/null | sort -n | awk '{print $2}')
if [[ ${#ALL[@]} -eq 0 ]]; then
echo "No e2e-verification-* directories under $EVIDENCE"
exit 0
fi
# Newest MIN_KEEP paths (never prune)
declare -A PROTECT
for ((i = ${#ALL[@]} - MIN_KEEP; i < ${#ALL[@]}; i++)); do
[[ $i -ge 0 ]] || continue
PROTECT["${ALL[$i]}"]=1
done
now=$(date +%s)
cutoff=$((now - KEEP_DAYS * 86400))
removed=0
checked=0
for dir in "${ALL[@]}"; do
[[ -n "${PROTECT[$dir]:-}" ]] && continue
mt=$(stat -c %Y "$dir" 2>/dev/null || echo 0)
(( checked++ )) || true
if (( mt < cutoff )); then
if [[ "$DRY_RUN" == true ]]; then
echo "Would remove (older than ${KEEP_DAYS}d): $dir"
else
rm -rf "$dir"
echo "Removed: $dir"
fi
(( removed++ )) || true
fi
done
if [[ "$DRY_RUN" == true ]]; then
echo ""
echo "Dry-run. Protected newest $MIN_KEEP dir(s). Set KEEP_DAYS=$KEEP_DAYS."
echo "To delete: KEEP_DAYS=$KEEP_DAYS bash $0 --apply"
else
echo "Done. Removed $removed director(y/ies); checked $checked (excluding protected)."
fi