19

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..

Ulrich Schwarz
  • 15,669
  • 4
  • 47
  • 58
Abhilash
  • 213
  • 1
  • 2
  • 5

1 Answers1

24

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.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • /data_gpfs/engageone/active-drive/E-Archive/SystemData/logrotation_test/test.log { daily copytruncate create 775 root wsdepl dateext dateformat .%Y.%m.%d rotate 30 maxage 30 missingok #notifempty sharedscripts postrotate cd /data_gpfs/engageone/active-drive/E-Archive/SystemData/logrotation_test gzip test.log.* mv /data_gpfs/engageone/active-drive/E-Archive/SystemData/logrotation_test/*.gz /data_gpfs/engageone/active-drive/E-Archive/SystemData/logrotation_test/backup endscript } – Abhilash Feb 12 '16 at 09:27
  • please check the above script where I have to rotate the file for 30 days and is moved into the backup directory after rotation.. so as I have used rotate 30 and maxage 30, will the oldest file be deleted after 30 days..? – Abhilash Feb 12 '16 at 09:29