Running
logrotate <conf>
Run with a config file (or directory)
logrotate -d <conf>
Debug: show what would happen, change nothing
Implies verbose and does not update the state file, so it is
safe to repeat.
logrotate -f <conf>
Force rotation even if not due
Forces a real rotation of every matching log, including the
postrotate scripts.
logrotate -v <conf>
Print what is being done
logrotate -s <file> <conf>
Use another state file
Handy for testing as a normal user: -s /tmp/state.status.
logrotate -l <file> <conf>
Write verbose output to a log file
logrotate -m <cmd> <conf>
Mail command used by the mail directive
logrotate --wait-for-state-lock <conf>
Wait instead of failing on a locked state
logrotate --version
Show the installed version
/var/lib/logrotate.status
State file: last rotation per log
Path varies: /var/lib/logrotate/status on Debian-family
systems.
systemctl list-timers logrotate.timer
See when the systemd timer runs it
Config structure
/path/to/app.log { ... }
Block: log path(s) and their directives
/var/log/a.log /var/log/b.log { ... }
One block for several logs
/var/log/app/*.log { ... }
Glob for the log files
include /etc/logrotate.d
Read all files of a directory
"/path with space.log" { ... }
Quote paths containing spaces
su <user> <group>
Rotate as this user and group
Needed when the log directory is writable by non-root users,
otherwise logrotate refuses with an insecure permissions
error.
Schedule and size
hourly
Rotate every hour
Only works if logrotate itself runs hourly.
weekly
Rotate once a week
monthly
Rotate once a month
yearly
Rotate when the year changes
rotate <count>
Keep this many old logs
rotate 0 deletes old logs; -1 keeps them (maxage may still
remove).
size <size>
Rotate only when larger (k, M, G)
Ignores the time interval entirely.
minsize <size>
Rotate when due and at least this big
maxsize <size>
Rotate when too big, even before due
maxage <days>
Delete rotated logs older than this
minage <days>
Skip logs younger than this
Files and naming
missingok
No error if the log does not exist
notifempty
Skip rotation if the log is empty
ifempty
Rotate empty logs too (default)
create <mode> <user> <group>
Make a new log after rotation
Example: create 0640 www-data adm. Omitted values are copied
from the old log.
nocreate
Do not create a new log
copytruncate
Copy, then truncate in place
For programs that cannot reopen their log. A few lines written
during the copy can be lost.
dateext
Use a date instead of a number
dateformat <fmt>
Date suffix, e.g. -%Y-%m-%d
Must sort alphabetically in time order.
olddir <dir>
Move rotated logs to a directory
Must be on the same filesystem unless copy or copytruncate is
used.
createolddir <mode> <user> <group>
Create the olddir if missing
extension <.ext>
Keep the extension at the end
start <n>
First rotation number
shred
Securely delete old logs
Scripts
postrotate ... endscript
Run commands after rotation
endscript must stand alone on its own line. Scripts run with
/bin/sh.
prerotate ... endscript
Run commands before rotation
sharedscripts
Run scripts once per block, not per log
With a glob this avoids reloading the service once for every
file.
firstaction ... endscript
Once before any log is rotated
lastaction ... endscript
Once after all logs are rotated
preremove ... endscript
Run before an old log is deleted
nosharedscripts
Scripts per log (default)