7

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

1 Answer 1

3

Replace

/var/log/management/abc.log.*[!.gz] 

with

/var/log/management/abc.log.*[0-9] 

Your combination of dateext with an empty dateformat is a nice way avoiding additional numbers in the filename!
When somebody else finds this answer, the next line is important:

nocreate 

And when you want to delete these files after 60 days, use

postrotate find /var/log/management -name "abc.log.*gz" -type f -mtime +60 -exec rm -f {} \; endscript 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.