logrotate suffix: dateext + rotate
Asked Answered
D

2

18

Is it possible to use dateext and rotate options at the same time?

config must look like this:

/var/log/verybig.log {
    monthly
    size=100M
    dateext
    dateformat .%Y%m
    rotate 5
    create
    missingok
    compress
}

and i must get:

/var/log/verybig.log
/var/log/verybig.log-201408.1.gz
/var/log/verybig.log-201408.2.gz
/var/log/verybig.log-201408.3.gz
/var/log/verybig.log-201408.4.gz
/var/log/verybig.log-201408.5.gz
/var/log/verybig.log-201409.1.gz
/var/log/verybig.log-201409.2.gz
/var/log/verybig.log-201409.3.gz
/var/log/verybig.log-201409.4.gz
/var/log/verybig.log-201409.5.gz

But now with this config, logrotate's debug tell me:

destination /var/log/verybig.201409.gz already exists, skipping rotation

Look like logrotate can't get multiple suffix-options, but maybe I just bad man-reader.

Using day in date format is workaround and I will not get format I want.

Demagogue answered 15/9, 2014 at 10:18 Comment(0)
L
20

You can use "date" as a suffix of the rotated file:

dateext dateformat -%Y-%m-%d-%s
Longer answered 2/11, 2014 at 18:29 Comment(3)
This works by adding the seconds to the date, in order to make the filename unique. So far, it has been the only way I've been able to get multiple rotations per day working correctly.Spyglass
And there is no ability to get %H%M%S (hours, minutes, and seconds) as with date. Only %s - seconds since 1970-01-01 (unix epoch ).Perfectionism
The minutes- and seconds specifiers,%M and %S are allowed in the dateformat string as of logrotate version 3.9.2; so dateformat .%Y-%m-%dT%H:%M:%S should work.Resent
L
7

You can use "date" as a suffix of the rotated file:

/tem/messages {
    rotate 5
    daily
    compress
    dateext
    dateformat -%Y-%m-%d.log
}

result: messages-2015-04-08.log.gz

Legalese answered 8/4, 2015 at 6:58 Comment(1)
Sorry, you didn't get the question. This config will cause duplication error if there are multiple rotations within the day.Nix

© 2022 - 2024 — McMap. All rights reserved.