#!/bin/bash # Prune Project Zomboid's own log archive. # # PZ rolls its logs into dated directories under Logs/ (logs_YYYY-MM-DD/, plus # loose YYYY-MM-DD_HH-MM_*.txt at the top) and never removes them. That is not # something logrotate can bound: it rotates by size, and no individual file here # ever reaches a sensible threshold -- the growth is in the *number* of files. # 112 directories and 146k files had accumulated to 18 GB before this existed. # # Files are owned by the container's UID, so this runs under podman unshare. set -euo pipefail LOGS="{{ zomboid_path }}/data/Logs" DAYS={{ zomboid_log_retention_days }} [[ -d "$LOGS" ]] || exit 0 before=$(podman unshare du -sh "$LOGS" 2>/dev/null | cut -f1) podman unshare find "$LOGS" -type f -mtime +"$DAYS" -delete 2>/dev/null || true # Second pass: the dated directories are empty once their files are gone. podman unshare find "$LOGS" -mindepth 1 -type d -empty -delete 2>/dev/null || true after=$(podman unshare du -sh "$LOGS" 2>/dev/null | cut -f1) echo "zomboid log prune: keeping ${DAYS}d, ${before} -> ${after}"