0

I have logrotate config like this:

/var/log/example*.log {
    weekly
    rotate 1
    missingok
    notifempty
    compress
}

Some of the example*.log files have existed for quite long time more than few months. I want to compress them with logrotate. But the config is newly added, thus it will only start to rotate them after another week.

rotating pattern: /var/log/example*.log  weekly (1 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/example-a.log
Creating new state
  Now: 2021-01-23 10:07
  Last rotated at 2021-01-23 10:00
  log does not need rotating (log has been already rotated)
considering log /var/log/example-b.log
Creating new state
  Now: 2021-01-23 10:07
  Last rotated at 2021-01-23 10:00
  log does not need rotating (log has been already rotated)
considering log /var/log/example-c.log
Creating new state
  Now: 2021-01-23 10:07
  Last rotated at 2021-01-23 10:00
  log does not need rotating (log has been already rotated)

I wonder is there a way to let the logrotate rotate files based on the creation time or mtime, when it is too old then compress them.

Another problem is the files matching wild card are all rotated together. No matter if the log file is newly created or not. I checked the /var/lib/logrotate/logrotate.status It seems like example*.log is treated as whole. That means all files match this pattern will be rotated at same day. For example: a new log file example-d.log has been added after 6 days of last rotation. Then it will be rotated the next day after it created. But I would like the newly added log example-d.log to rotate after 1 week. Is there any other tool can rotate logs like what I want?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.