17

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.

strizhechenko
  • 408
  • 2
  • 6
  • 16

2 Answers2

18

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

dateext dateformat -%Y-%m-%d-%s
Nahuel Ianni
  • 3,177
  • 4
  • 23
  • 30
sfab
  • 181
  • 3
  • 4
    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. – Jason Denney Jul 11 '16 at 22:27
  • 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 ). – kyb Jun 18 '18 at 09:15
6

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

Sam Hooke
  • 21
  • 5
Leo
  • 119
  • 2
  • 10