brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: logrotate -d shows what a rotation would do without touching a file

Linux
~/tips/tip-logrotate-debug-dry-run

sudo logrotate -d /etc/logrotate.d/myapp

Test a logrotate config and see what it would rotate, without changing any log.

When I write a new logrotate config, I don’t want to wait for tomorrow’s run to find out it has a typo in it. logrotate has a debug mode that reads the config, works out what it would rotate and prints its reasoning, and leaves the logs alone.

sudo logrotate -d /etc/logrotate.d/myapp

With -d (long form --debug) nothing changes: no file gets renamed, compressed or deleted, and the state file where logrotate remembers its earlier runs isn’t updated either. What you get instead is the decision per log file: which settings it picked up, whether the file is due (or log does not need rotating) and which file names it would create.

To check everything the daily run handles, including every snippet in /etc/logrotate.d/, point it at the main config:

sudo logrotate -d /etc/logrotate.conf

A syntax error or an unknown directive shows up right away, and that alone is why I’d run this after every edit.

The catch: since the state file stays as it is, a dry run says “not yet” for a log that was rotated recently, even when your new settings are fine. To actually see a rotation happen, -f (--force) rotates even when logrotate thinks it isn’t needed. That one does change files, so I’d only use it once the debug output looks right, together with -v so it tells you what it’s doing.

Further reading: logrotate(8) man page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link