I want to compress some log files which have name format as abc.log.yyyy-MM-dd
and then delete the compressed log file (abc.log.yyyy-MM-dd.gz) after x days.I don't want logrotate to rotate files(i.e. create new files), I only want it to compress and delete the compressed files after x days.
I tried using this pattern to only compress files:
To Compress files:
/var/log/management/abc.log.*[!.gz]
su x y
daily
nocreate
missingok
compress
dateext
dateformat
rotate 6 #If I don't provide this parameter, files are deleted as soon as they
are compressed
}
To delete compressed files after x days:
/var/log/management/abc.log.*.gz* {
su x y
daily
rotate x
maxage x
}
After 2 execution of logrotate, the result is as follows:
abc.log.2019-05-20.gz.1.gz
abc.log.2019-05-21.gz.1
abc.2019-05-22.gz
The compressed and rotated files is compressed again.
Can someone tell the exact regex pattern for filename that should be used
Best Answer
Replace
with
Your combination of
dateext
with an emptydateformat
is a nice way avoiding additional numbers in the filename!When somebody else finds this answer, the next line is important:
And when you want to delete these files after 60 days, use