2

So this is driving me crazy. I'm running logrotate on a weekly basis for a few different logs and it works as I expect. However, the log rotation occurs on Sunday, which coincides with the completion of some processing that logs to those directories which are to be rotated. In a nutshell, I would like to rotate these log files on Thursday, prior to this processing, and I would like to keep the "fix" within the logrotate configurations themselves (vice manually running logrotate --force, or placing this within the script).

I'm running RHEL5 with the following configurations:

cat /etc/logrotate.d/custom
/var/log/mpxx/mpxx_log {
  daily
  rotate 30
  compress
  missingok
  olddir /var/log/mpxx.old/
  create 644 user user
  dateext
}
/var/log/mpxx/repo.log /var/log/mpxx/stop_repo.log {
  weekly
  rotate 90
  compress
  missingok
  olddir /var/log/mpxx.old/
  create 644 user user
  dateext
}

cat /var/lib/logrotate.status
"/var/log/mpxx/repo.log" 2015-4-12
"/var/log/mpxx/stop_repo.log" 2015-4-12

I manually rotated the logs with logrotate --force /etc/logrotate.d/custom on Friday April 10th when I noticed the issue. Then, I manually edited the logrotate.status file to reflect the following:

"/var/log/mpxx/repo.log" 2015-4-9
"/var/log/mpxx/stop_repo.log" 2015-4-9

Unfortunately, my manual run of logrotate, and my edits to the status file did not keep logrotate from rotating the log files on April 12th, as noted previously.

How can I force logrotate to perform the rotation on a weekly basis, but on a specific day of the week? My searches and research haven't turned up much.

Thanks in advance!

mjshort
  • 73
  • 1
  • 6

1 Answers1

3

I know this is old but I've just had to implement something like this myself and found this question and thought I'd answer it.

logrotate(8) has this built-in:

       weekly [weekday]
              Log  files  are  rotated  once  each weekday, or if the date is advanced by at least 7 days since the last rotation (while ignoring the exact time).  The weekday interpretation is following:  0
              means Sunday, 1 means Monday, ..., 6 means Saturday; the special value 7 means each 7 days, irrespectively of weekday.  Defaults to 0 if the weekday argument is omitted.
scottsome
  • 432
  • 1
  • 4
  • 5
  • This is available in newer versions of logrotate only. In CentOS 7 there is logrotate 3.8.6, which does not allow to add a weekday. I also checked some newer OSes (CentOS 8, Oracle Linux 8, Ubuntu 20.04, Ubuntu 22.04), and they have logrotate 3.14.0 or 3.19.0, which support a weekday number. – nobody May 03 '22 at 08:38