Wednesday, 23 July 2014

How to add date to logrotate files- EXPLAINED!

By default, when log files are rotated they are first renamed and after compressed if this option is enabled.
Those moved files get extension in numbers so depending of how many rotation cycles you have it looks something like this

server# pwd
/var/log
server# ls |grep messages
messages
messages.1
messages.2
messages.3
messages.4


In case that you want to change these number to date expression you have to add this line to /etc/logrotate.conf

.
.
dateext
.
.

On next rotation cycle your log files will look like this

.
.
messages-20140209
messages-20140216
messages-20140223
.
.

No comments: