Back to lessons

Hosting Operations

Dry-Run Logrotate Before Touching Logs

You need to understand what logrotate would do without compressing, renaming, or truncating real logs.

Command

logrotate -d /etc/logrotate.conf 2>&1 | sed -n '/rotating pattern/p;/considering log/p;/error:/p'

What changed

Nothing changes. The -d flag runs logrotate in debug mode and the pipe extracts useful decision lines.

Danger

safe

When to use it

Use before changing logrotate rules or when logs are growing and you need to see whether policies match them.

When not to use it

Do not use -f unless you intentionally want to force rotation; this lesson is debug-only.

Undo or recovery

No undo needed because the command is read-only in debug mode.

Expected output

rotating pattern and considering log lines from logrotate debug output.

demo script

Disposable terminal steps

  1. logrotate -d /etc/logrotate.conf
  2. logrotate -d /etc/logrotate.conf 2>&1 | sed -n '/rotating pattern/p;/considering log/p;/error:/p'

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ logrotate -d /etc/logrotate.conf
reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file nginx
reading config file app
rotating pattern: /var/log/nginx/*.log  after 1 days (14 rotations)
considering log /var/log/nginx/access.log
  log does not need rotating
considering log /var/log/nginx/error.log
  log does not need rotating
rotating pattern: /var/log/app/app.log  52428800 bytes (7 rotations)
considering log /var/log/app/app.log
  log does not need rotating
::exit-code::0
$ logrotate -d /etc/logrotate.conf 2>&1 | sed -n '/rotating pattern/p;/considering log/p;/error:/p'
rotating pattern: /var/log/nginx/*.log  after 1 days (14 rotations)
considering log /var/log/nginx/access.log
considering log /var/log/nginx/error.log
rotating pattern: /var/log/app/app.log  52428800 bytes (7 rotations)
considering log /var/log/app/app.log
::exit-code::0

YouTube Short

Dry-run logrotate first.

Do not force log rotation to see what will happen. Debug mode explains the matching rules without touching the logs.

LinkedIn hook

Logrotate can explain its plan without rotating anything.

Question: Do you dry-run logrotate before changing rotation rules?

experiments

A/B tests to run

Metric: save_rate

A: Logrotate can explain its plan first.

B: Dry-run before forcing rotation.