logrotate working but ignoring size
Asked Answered
Q

1

7
  • CentOS v.7
  • Logrotate v.3.8.6

I set logrotate to rotate when file reaches 5M but it ignores it, if I add daily it will rotate daily regardless of size, i tried with size, minsize and maxsize all the same the only difference is with "size" it doesnt even refer to it in the output, here is my config and output of logrotate -vdf /etc/logrotate.d/maillog

(the actual log file size when running the following tests was 45K)

(the conf file is the same for all tests only the size parameter changed)

/var/log/maillog {
    size 5M
    rotate 50
    create 644 root root
    dateext
    dateformat -%Y-%m-%d_%H_%s
    notifempty
    postrotate  systemctl restart rsyslog
        systemctl restart postfix
    endscript }

SIZE:

logrotate -vdf /etc/logrotate.d/maillog

reading config file /etc/logrotate.d/maillog
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/maillog  forced from command line (50 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/maillog
  log needs rotating
rotating log /var/log/maillog, log->rotateCount is 50
Converted ' -%Y-%m-%d_%H_%s' -> '-%Y-%m-%d_%H_%s'
dateext suffix '-2017-12-19_13_1513689486'
glob pattern '-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
fscreate context set to unconfined_u:object_r:var_log_t:s0
renaming /var/log/maillog to /var/log/maillog-2017-12-19_13_1513689486
creating new /var/log/maillog mode = 0644 uid = 0 gid = 0
running postrotate script
running script with arg /var/log/maillog: "
    systemctl restart rsyslog
    systemctl restart postfix
"

No reason for "log needs rotating" is given.

MINSIZE:

logrotate -vdf /etc/logrotate.d/maillog

reading config file /etc/logrotate.d/maillog
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/maillog  forced from command line (50 rotations)
empty log files are not rotated, only log files >= 5242880 bytes are rotated, old logs are removed
considering log /var/log/maillog
  log needs rotating
rotating log /var/log/maillog, log->rotateCount is 50
Converted ' -%Y-%m-%d_%H_%s' -> '-%Y-%m-%d_%H_%s'
dateext suffix '-2017-12-19_13_1513689869'
glob pattern '-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
fscreate context set to unconfined_u:object_r:var_log_t:s0
renaming /var/log/maillog to /var/log/maillog-2017-12-19_13_1513689869
creating new /var/log/maillog mode = 0644 uid = 0 gid = 0
running postrotate script
running script with arg /var/log/maillog: "
    systemctl restart rsyslog
    systemctl restart postfix
"

Here it shows, "only log files >= are rotated" but no reason for "log needs rotating" is given.

MAXSIZE:

reading config file /etc/logrotate.d/maillog
Allocating hash table for state file, size 15360 B

Handling 1 logs

rotating pattern: /var/log/maillog  forced from command line (50 rotations)
empty log files are not rotated, log files >= 5242880 are rotated earlier, old logs are removed
considering log /var/log/maillog
  log needs rotating
rotating log /var/log/maillog, log->rotateCount is 50
Converted ' -%Y-%m-%d_%H_%s' -> '-%Y-%m-%d_%H_%s'
dateext suffix '-2017-12-19_13_1513690859'
glob pattern '-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
fscreate context set to unconfined_u:object_r:var_log_t:s0
renaming /var/log/maillog to /var/log/maillog-2017-12-19_13_1513690859
creating new /var/log/maillog mode = 0644 uid = 0 gid = 0
running postrotate script
running script with arg /var/log/maillog: "
    systemctl restart rsyslog
    systemctl restart postfix
"

Here it shows, "log files => are rotated" but no reason for "log needs rotating" is given.

Why is it ignoring file size when rotating?

Quire answered 19/12, 2017 at 13:50 Comment(0)
B
8

You're running logrotate with -f, in that scenario it's always going to force a rotation with a complete lack of regard for your other options:

https://manpages.debian.org/jessie/logrotate/logrotate.8.en.html

-f, --force Tells logrotate to force the rotation, even if it doesn't think this is necessary.

It gives you no reason because you in fact were the reason-giver.

Bianchi answered 23/5, 2018 at 21:7 Comment(1)
Oh the irony to see that question has more upvotes than the answer. @Sruli: This should be upvoted!Shizukoshizuoka

© 2022 - 2024 — McMap. All rights reserved.