[olug] Log Retention

Dave Thacker dthacker at bluestrain.net
Mon Dec 12 02:49:26 UTC 2011


On Sunday, December 11, 2011 07:11:28 PM T. J. Brumfield wrote:
> I feel stupid asking what should be a fairly elementary question, but it is
> something I've never had to do on a Linux Apache box before. Log retention
> policies were always in place before I got there, or we had enough storage
> that we've never had to worry about it. (Not to mention that everyplace
> I've worked has been predominately a Microsoft-only shop). But I have a VPS
> with limited disk space and need a way to manage log retention.
> 
> I need to make sure I've got something in place to keep log files in check.
> I don't want to turn off logging, but I need to rotate logs at file size X
> and then delete logs when I get over Y number of logs so I keep my overall
> log storage at a fairly constant number.
> 
> I need to do this for MySQL, Apache, PHP, Murmur and local system logs
> because I can't afford to let any logs run me out of disk space.
> 
> I'm running Fedora 16 (because I wanted to familiarize myself with
> systemd).
> 
I second Chris's reply in this thread.  logrotate is the tool for the job.  
Most apps like apache and mysql will drop a configuration entry in 
logrotate.d.  Here's a sample entry for cups from my box:

0> more cups                                                                                                                                                                                  
/var/log/cups/*log {                                                                                                                                                                          
        daily                                                                                                                                                                                 
        missingok                                                                                                                                                                             
        rotate 7                                                                                                                                                                              
        sharedscripts                                                                                                                                                                         
        postrotate
                if [ -e /var/run/cups/cupsd.pid ]; then
                        invoke-rc.d --quiet cups force-reload > /dev/null
                        sleep 10
                fi
        endscript
        compress
        notifempty
        create 640 root lpadmin
}

Enjoy

DT



More information about the OLUG mailing list