| Flag | Usage |
|---|---|
| -d | debug mode : (implies -v : verbose mode) no changes will be made to the logs or to the state file |
| -f |
|
|
-s stateFile --state stateFile |
|
| Directive | Usage |
|---|---|
| compress | compress old versions of logfiles with gzip |
| compresscmd /bin/bzip2 | compress logs with /bin/bzip2 instead of the default gzip
Should be used with compressext, otherwise compressed files get a .gz extension.
|
| compressext .bz2 | give compressed files a .bz2 extension |
| copytruncate | To be used when the program writing into the logfile is not able to close and release it.
create a copy of the logfile, then truncate the original logfile.
There is a very small time slice between copying the file and truncating it, so some logging data might be lost.
|
| create mode user group | immediately after rotation (before the postrotate script is run), create a new logfile with :
|
| dateext | when rotating logs, instead of appending numbers to successive rotations (from 1 (newest) to n (oldest)), append the log rotation date
|
| ifempty | rotate the log file even if it is empty (default value) |
| missingok | don't issue an error if the log file is missing |
| notifempty | do not rotate the log file when it is empty |
| olddir path/to/directory | move logs into path/to/directory for rotation
|
| rotate n | rotate log files n times before removing them. In other words : keep n rotation intervals (days / weeks / months / ...) of logs.
this does not enforce n as the absolute maximum number of files within the log directory :
|
current date > date in state file, the file is rotated (source).cat << EOF > /etc/logrotate.d/serviceName EOF
/var/log/tomcat8/catalina.out /var/log/tomcat8/*log { }
/etc/cron.d/logrotate /etc/cron.daily/logrotate
serviceName='cyberwatch_backup.logrotate' rotatedFileName=$(awk '/{$/ { result=gensub(/^.*\/(.*)$/, "\\1", 1, $1); print result }' "/etc/logrotate.d/$serviceName") grep "$rotatedFileName" /var/lib/logrotate/logrotate.status
"/backup/backup_cyberwatch.sql.gz" 2026-1-29-15:44:33