Kalaiyarasan
Kalaiyarasan

Reputation: 297

Compress and delete the logs in logrotate

I want to compress the logs older than 30 days and delete older than 90 days through logrotate. Can you please help me here how I need to configurate in logrotate conf file.

Logs has been creating according to time. I need to take backup only subversion logs from this path.

[svnadmin@svnarapp01:/opt/svn/logs/svnarapp01]ls subversion_201*
subversion_2014_12_14_00_00_00.log
subversion_2014_12_29_00_00_00.log  
subversion_2015_01_13_00_00_00.log
subversion_2014_12_15_00_00_00.log  
subversion_2014_12_30_00_00_00.log  
subversion_2015_01_14_00_00_00.log
subversion_2014_12_16_00_00_00.log  
subversion_2014_12_31_00_00_00.log  
subversion_2015_01_15_00_00_00.log

Logs will compress older than 30 days and delete older than 90 days. This process will run daily.

Upvotes: 1

Views: 13904

Answers (2)

Daniil
Daniil

Reputation: 115

maxage will not be applied to .gz files as they are not .log files. You could try to define postrotate script as follows:

postrotate
       find /path/to/log/ -name "*.log.*.gz" -mtime +7 -delete
endscript

Please adjust the path and mtime based on your requirements.

Upvotes: 4

user4497978
user4497978

Reputation:

You can try define something like this in logrotate.conf

/opt/svn/logs/svnarapp01/subversion_*.log {
    monthly
    compress
    maxage 90
}

This will compress log files older than 30 days and remove logs older than 90 days.  You can find more parameters in logrotate man page.

Upvotes: 0

Related Questions