Judging by the timestamps on my systems, logrotate does its daily log rotation when logrotate is run by cron. However, if I run it earlier than that it doesn't rotate the files. How does logrotate know if should rotate them or not, does it keep a history or perhaps use timestamps?
I believe it's the content of the state file, which is my case is
/var/lib/logrotate.status
. Each file has one line, which is the date on which it was last rotated; if you run logrotate on such a date that a given file is due for rotation, given the number of days between current date and the date in the file (1 for daily, 7 for weekly, etc.), the file will be rotated.logrotate doesn't seem to care at what time of day it's run; even if it usually runs at 2355, if you were to run it at 0130 instead, it would still rotate files marked daily and last done yesterday; but having done so it would put today's date into the state file (against any rotated files), so a second run at 2355 would do nothing.
From the logrotate man page:
It runs on
crontab
schedules. You just need to find whichcrontab
schedule haslogrotate
configured. Normally, it's in the daily/etc/cron.daily/
. The generic crontab schedules are available in/etc/crontab
.Sample below: