Logrotation – rotate and maxage command

logrotate

Can anybody please explain me about the function of 'rotate' and 'maxage' in logrotation as this is very confusing .

consider am using the below values in my script:

rotate 30
maxage 30

Thank you..

Best Answer

Both of them define how many logfiles you want to keep. While rotate accepts a number of files, maxage will parse its value as a time. So if you rotate your log weekly you can either use rotate 2 or maxage 14. Keep in mind that maxage will delete old log files after the given time so if there are no new log entries, logrotate will not create new archives but it will delete the old ones while rotate won't do that.

The best option is to combine both of them:

weekly
rotate 4
maxage 60

This will rotate the log file every week and there won't be more than 4 archives (one month). But if the files are older than 60 days, logrotate will remove them.

Related Question