logrotate suffix: dateext + rotate

strizhechenko picture strizhechenko · Sep 15, 2014 · Viewed 28.2k times · Source

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.

Answer

sfab picture sfab · Nov 2, 2014

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

dateext dateformat -%Y-%m-%d-%s