logrotation - rotate and maxage command
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 videos on Youtube
Abhilash
Updated on November 29, 2022Comments
-
Abhilash over 1 year
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..
-
Admin about 8 years/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 }
-
Admin about 8 yearsplease 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..?