Files
deploy_home/ansible/roles/podman/templates/zomboid/zomboid-log-prune.sh.j2
T
Bastian de BylandClaude Opus 5 91d9f6b419 fix: actually bound the Zomboid log archive, which logrotate could not
The logrotate config added with the Sophie overhaul claimed to bound PZ's own
logs. It did not. data/Logs had reached 18 GB across 112 entries and 146k
files, and rotation had never once fired there.

Two reasons, both wrong assumptions on my part. PZ rolls its logs into dated
directories -- logs_2025-12-14/ through logs_2026-08-26/, up to 279 MB each --
so the Logs/*.txt glob only ever matched a handful of loose files at the top.
And it rotates by size: not one file in that tree exceeds 100M, because the
growth is in the number of files, not the size of any of them.

Age-based pruning is the right tool, so this adds a daily zomboid-log-prune
timer keeping 14 days and deleting the emptied directories behind it. It runs
under podman unshare, since the files belong to the container's UID.

logrotate keeps server-console.txt, which is a single ever-growing file and
genuinely is what it is good at. Narrowed its scope to say so rather than
implying coverage it never had.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 02:34:30 -04:00

25 lines
1.1 KiB
Django/Jinja

#!/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}"