Clearing out old JournalD Entries



Published: 2019-09-19 11:03:37 +0000
Categories: BASH,

Language

BASH

Description

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

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

Keywords

systemd, logs, rotation, clearing, journald, journal, binary logs,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter