November 25, 2024, 04:10:50 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: compress the log files using logrotate  (Read 7445 times)

Offline skmdu

  • New Member
  • Posts: 1
compress the log files using logrotate
« 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.

Offline dragoncity99

  • LST CareTaker
  • Experienced
  • *****
  • Posts: 551
Re: compress the log files using logrotate
« Reply #1 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