Clearing out old JournalD Entries (BASH)
My NAS sits there quietly doing it's job most of the time. However, recently I needed to troubleshoot a cron that appeared not to be running, so went looking for log entries.
Turns out Debian 8's default behaviour was to send cron loglines to journald
only (i.e. no passthrough to rsyslog
).
To make matters worse, there's no journal rotation set up by default, so the loglines go back _months_ and JournalD is hysterically bad at actually getting through them in a reasonable time
So, before fixing the lack of rotation (by setting SystemMaxUse
in /etc/systemd/journald.conf
) I wanted to rotate the logs and then clear out stuff older than about a month
This snippet details how to rotate and then vacuum JournalD's logs based on a time interval
Details
- Language: BASH
Snippet
# this will fail on Debian Jessie, as SystemD didn't support it yet
# Rotate and then clear out entries older than 1 month
#
# Vacuuming only affects archived journals, so you must rotate first
journalctl --rotate
journalctl --vacuum-time=1month
# If on Debian 8 (or anything with an older SystemD version)
# then we need to set the retention config, there's no way to
# manually trigger
#
sed -i 's/#MaxRetentionSec=/MaxRetentionSec=1month/' /etc/systemd/journald.conf
systemctl restart systemd-journald
systemctl status systemd-journald