Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 195787 - =app-admin/logrotate-3.7.2 behavior doesn't match documentation
Summary: =app-admin/logrotate-3.7.2 behavior doesn't match documentation
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High minor (vote)
Assignee: Daniel Gryniewicz (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on: 192468
Blocks:
  Show dependency tree
 
Reported: 2007-10-13 23:43 UTC by ta2002
Modified: 2011-04-17 15:01 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ta2002 2007-10-13 23:43:10 UTC
The man page for logrotate claims:

weekly  Log files are rotated if the current weekday is less then the weekday
        of the last rotation or if more then a week has passed since the last
        rotation. This is normally the same as rotating logs on the first day
        of the week, but if logrotate is not being run every night a log
        rotation will happen at the first valid opportunity.

It doesn't work that way. I have three machines (on continuously with logrotate getting run every day), and the weekly rotations get done on different days of the week for each machine (I would actually prefer that the all get done on the same day).

Yes, I could kludge this into working by editing /var/lib/logrotate.status and changing the days of the last rotations, but I seem to remember this working as described many years ago on another distribution.

Some relevant parts from two of the systems:

a$ dog /var/lib/logrotate.status
logrotate state -- version 2
"/var/log/messages" 2007-10-10
"/var/log/portage/elog/summary.log" 2007-9-26
"/var/log/wtmp" 2007-10-1

a$ ls -al /var/log/messages*
-rw------- 1 root root 97522 2007-10-13 23:30:01 /var/log/messages
-rw------- 1 root root  8255 2007-10-10 03:10:01 /var/log/messages.1.gz
-rw------- 1 root root 15180 2007-10-03 03:10:01 /var/log/messages.2.gz

b$  dog /var/lib/logrotate.status
logrotate state -- version 2
"/var/log/messages" 2007-10-8
"/var/log/portage/elog/summary.log" 2007-9-16
"/var/log/wtmp" 2007-10-1

b$ $ ls -al /var/log/messages*
-rw------- 1 root root 95341 2007-10-13 23:28:50 /var/log/messages
-rw------- 1 root root  6358 2007-10-08 03:10:01 /var/log/messages.1.gz
-rw------- 1 root root  6563 2007-10-01 03:10:01 /var/log/messages.2.gz
-rw------- 1 root root  8996 2007-09-24 03:10:02 /var/log/messages.3.gz
-rw------- 1 root root 37864 2007-09-17 03:10:01 /var/log/messages.4.gz

Note that as a new install, I don't yet have five weeks of logs for system a.
Comment 1 Daniel Gryniewicz (RETIRED) gentoo-dev 2009-03-10 02:06:04 UTC
Docs have been updated in 3.7.8
Comment 2 ta2002 2010-03-16 20:22:42 UTC
I am still not seeing anything good happening here. With weekly rotation, not only do I have files on different computers getting rotated on different days, I have files on the SAME computer getting rotated on different days.

ls -al /var/log/messages* /var/log/smartd_sda*
-rw------- 1 root root 124829 2010-03-16 20:20:01 /var/log/messages
-rw------- 1 root root  75879 2010-02-22 03:10:02 /var/log/messages-20100222.gz
-rw------- 1 root root 157915 2010-03-01 03:10:01 /var/log/messages-20100301.gz
-rw------- 1 root root  91741 2010-03-08 03:10:01 /var/log/messages-20100308.gz
-rw------- 1 root root  99875 2010-03-15 03:10:01 /var/log/messages-20100315.gz
-rw------- 1 root root  10656 2010-03-16 14:10:32 /var/log/smartd_sda
-rw------- 1 root root    791 2010-02-17 03:10:02 /var/log/smartd_sda-20100217.gz
-rw------- 1 root root    978 2010-02-24 03:20:01 /var/log/smartd_sda-20100224.gz
-rw------- 1 root root    971 2010-03-03 03:10:02 /var/log/smartd_sda-20100303.gz
-rw------- 1 root root    951 2010-03-10 03:10:01 /var/log/smartd_sda-20100310.gz


ls -al /var/log/messages* /var/log/smartd_sda*
-rw------- 1 root root  8437 2010-03-16 19:42:41 /var/log/messages
-rw------- 1 root root 95779 2010-02-21 03:10:01 /var/log/messages-20100221.gz
-rw------- 1 root root 13569 2010-02-28 03:10:05 /var/log/messages-20100228.gz
-rw------- 1 root root  2103 2010-03-07 03:10:02 /var/log/messages-20100307.gz
-rw------- 1 root root  4538 2010-03-14 03:10:03 /var/log/messages-20100314.gz
-rw------- 1 root root   751 2010-03-16 20:04:01 /var/log/smartd_sda
-rw------- 1 root root  1600 2010-02-22 03:10:01 /var/log/smartd_sda-20100222.gz
-rw------- 1 root root  1000 2010-03-01 03:10:02 /var/log/smartd_sda-20100301.gz
-rw------- 1 root root   716 2010-03-08 03:10:01 /var/log/smartd_sda-20100308.gz
-rw------- 1 root root   863 2010-03-15 03:10:02 /var/log/smartd_sda-20100315.gz
Comment 3 Daniel Gryniewicz (RETIRED) gentoo-dev 2010-03-17 14:48:52 UTC
From the man page:

       weekly Log files are rotated if the current weekday is less than  the  weekday
              of  the  last rotation or if more than a week has passed since the last
              rotation. This is normally the same as rotating logs on the  first  day
              of the week, but it works better if logrotate is not run every night.

This means that it will rotate each file a week after it was last rotated, not on a specific day of the week.  If all files exist when you first start logrotate, it will rotate them all, and they should stay in sync, in general.
Comment 4 ta2002 2010-03-20 20:20:45 UTC
My understanding is completely different.

"Log files are rotated if the current weekday is less then the weekday of the last rotation OR [emphasis added] if more then a week has passed since the last rotation."

This means that all log files should be rotated on the first day of the week (and the man page seems to confirm that - "This is normally the same as rotating logs on the first day of the week").

The logic seems clear:

If (current weekday < weekday of last rotation)
    {rotate}
elsif (one week has passed since last rotation)
    {rotate}

But the program does not behave that way.
Comment 5 Sven 2010-03-21 10:22:57 UTC
(In reply to comment #4)
> My understanding is completely different.
> 
> "Log files are rotated if the current weekday is less then the weekday of the
> last rotation OR [emphasis added] if more then a week has passed since the last
> rotation."
> 
> This means that all log files should be rotated on the first day of the week
> (and the man page seems to confirm that - "This is normally the same as
> rotating logs on the first day of the week").
> 
> The logic seems clear:
> 
> If (current weekday < weekday of last rotation)
>     {rotate}
> elsif (one week has passed since last rotation)
>     {rotate}
> 
> But the program does not behave that way.

Shouldn't you report the bug upstream rather than here?
Comment 6 Daniel Gryniewicz (RETIRED) gentoo-dev 2010-03-23 00:15:10 UTC
My reading of that is *only* if you only run logrotate weekly.  Otherwise, the first day that is >1 week from the last rotation (so if it was last rotated on a tuesday, that would be the next tuesday) it will rotate.
Comment 7 ta2002 2011-04-13 20:40:39 UTC
(In reply to comment #5)

> Shouldn't you report the bug upstream rather than here?

No, because it is a GENTOO bug. No other distribution does it this way.

There is a patch causing this:

/usr/portage/app-admin/logrotate/files/logrotate-3.7.7-weekly.patch

I was very disappointed to see this patch still in logrotate-3.7.9-r1.


(In reply to comment #6)

> My reading of that is *only* if you only run logrotate weekly.
> Otherwise, the first day that is >1 week from the last rotation
> (so if it was last rotated on a tuesday, that would be the next
> tuesday) it will rotate.

What part of "Log files are rotated if the current weekday is less
than the weekday of the last rotation" don't you understand?

Look at the (unpatched) code (logrotate.c). The intent is clear.

Actually, this looks like your patch:

diff --exclude-from=/home/dang/.scripts/diffrc -up -ruN logrotate-3.7.7.orig/logrotate.c logrotate-3.7.7/logrotate.c

Its purpose completely escapes me.
Comment 8 Sven 2011-04-13 20:56:57 UTC
(In reply to comment #6)
> My reading of that is *only* if you only run logrotate weekly.  Otherwise, the
> first day that is >1 week from the last rotation (so if it was last rotated on
> a tuesday, that would be the next tuesday) it will rotate.

Let me support throw_away_2002. The man page gives a simple rule (as quoted by throw_away_2002) for when weekly rotation happens.

In your example, if the log was last rotated on tuesday (let's assume tuesday is equal to the integer number 2) and logrotate is run on monday (let's assume monday is equal to the integer number 1), then the log is supposed to be rotated since, as the man page states, the number 1 (monday) is smaller/less than 2 (tuesday).
Now, if the log has been rotated on monday, there is no other weekday with a smaller integer number (if you assume that sunday is 7). So hence the second condition: as the man pages states, a log is also supposed to be rotated, if more than a week has passed since the last rotation.

In other words: logrotate tries to rotate every monday, if it is executed on monday. Otherwise, it will rotate the logs on the first day of the week, it is executed.

I have to agree with throw_away_2002, that the words in the man page are perfectly clear about that.

It might seem to be an odd algorithm, but that is how upstream intended it. And, if correctly implemented, this algorithm leads to one rotation a week, if logrotate is run at least once a week.
Comment 9 Sven 2011-04-13 21:07:52 UTC
Correct me if I'm wrong, but the original code (the one before the weekly.path is applied) will not actually rotate a log, if logrotate is run every monday, at the same hour, minute, and second. Then, the difference between mktime(&now) and mktime(&state->lastRotated) is exactly equal to 7*24*3600, but not larger (as the code requires).
Comment 10 Daniel Gryniewicz (RETIRED) gentoo-dev 2011-04-14 12:50:49 UTC
3.7.9-r1 was a security bump.  As such, it contains (by policy) only the patches fixing the security issues.
Comment 11 ta2002 2011-04-14 13:40:43 UTC
(In reply to comment #9)
> Correct me if I'm wrong, but the original code (the one before the weekly.path
> is applied) will not actually rotate a log, if logrotate is run every monday,
> at the same hour, minute, and second. Then, the difference between mktime(&now)
> and mktime(&state->lastRotated) is exactly equal to 7*24*3600, but not larger
> (as the code requires).

OK, I will correct you. :) It works absolutely fine without the patch (and the way it is supposed to work, too - all of the log files get rotated on Sunday). No other distribution uses a patch like this, and if it didn't work, I assume that upstream would have heard about it.
Comment 12 Daniel Gryniewicz (RETIRED) gentoo-dev 2011-04-17 15:01:54 UTC
Fixed.