Linux Forums - Linux Help,Advice & support community:LinuxSolved.com

Others => Miscellaneous => Topic started by: skmdu on October 12, 2009, 10:23:52 AM

Title: compress the log files using logrotate
Post by: skmdu on October 12, 2009, 10:23:52 AM
Hi,
I have an application which creates the logs in a date wise.
like,
Code:

tomcat_access_log.2009-09-12.log
tomcat_access_log.2009-09-11.log
tomcat_access_log.2009-09-10.log
tomcat_access_log.2009-09-09.log
tomcat_access_log.2009-09-08.log
tomcat_access_log.2009-09-07.log

Now my requirement is to compress all the log files and keep only last 5 days compressed logfiles always.

For ex:
Code:

If today is 10/09/2009 ( mm/dd/yyyy)
then my log directory ( /var/log/appn) should looks like,

tomcat_access_log.2009-10-09.log
tomcat_access_log.2009-10-08.log.gz
tomcat_access_log.2009-10-07.log.gz
tomcat_access_log.2009-10-06.log.gz
tomcat_access_log.2009-10-05.log.gz
tomcat_access_log.2009-10-04.log.gz


I tried to get it done through the logrotate,

Before logrotate


-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-10-01.log
-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-09-30.log
-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-09-29.log
-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-09-28.log
-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-09-27.log
-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-09-26.log
-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-09-25.log
-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-09-24.log
-rw-r--r-- 1 root    root          0 Oct  9 02:46 tomcat_access_log.2009-09-23.log


content of /etc/logrotate.conf

/var/log/appn/*.log {
 daily
 compress
 rotate 5
}

After logrotate

-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-10-01.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-10-01.log
-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-09-30.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-09-30.log
-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-09-29.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-09-29.log
-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-09-28.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-09-28.log
-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-09-27.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-09-27.log
-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-09-26.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-09-26.log
-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-09-25.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-09-25.log
-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-09-24.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-09-24.log
-rw-r--r-- 1 root    root         20 Oct  9 02:54 tomcat_access_log.2009-09-23.log.1.gz
-rw-r--r-- 1 root    root          0 Oct  9 02:54 tomcat_access_log.2009-09-23.log

How to achieve my need mentioned above?  Any help is really appreciated.
Title: Re: compress the log files using logrotate
Post by: dragoncity99 on October 29, 2009, 03:10:17 PM
Have you restarted the logrotate.conf after changing the ruleset by the way ?

Better check the documentation as well:
# man logrotate