0

I have apache setup to generate new log files everyday:

CustomLog "|/usr/sbin/rotatelogs -f /var/log/apache2/access.log.%Y-%m-%d-%H_%M 86400" combined

Then I'm trying to use logrotate to zip these files:

/var/log/apache2/access.log.* {
    compress
    create 0644 root root
    daily
    delaycompress
    missingok
    maxage 7
}

What happens is that I get a bunch of files that look like:

-rw-r--r-- 1 root root        20 2011-11-26 06:49 access.log.2011-11-21-00_00.1.1.3.gz
-rw-r--r-- 1 root root        33 2011-11-26 06:49 access.log.2011-11-21-00_00.2.gz.3.gz
-rw-r--r-- 1 root root        20 2011-11-26 06:49 access.log.2011-11-21-00_00.3.gz.3.gz
-rw-r--r-- 1 root root        20 2011-11-26 06:49 access.log.2011-11-22-00_00.1.1.3.gz
-rw-r--r-- 1 root root        33 2011-11-26 06:49 access.log.2011-11-22-00_00.2.gz.3.gz
-rw-r--r-- 1 root root        20 2011-11-26 06:49 access.log.2011-11-22-00_00.3.gz.3.gz
-rw-r--r-- 1 root root        20 2011-11-26 06:49 access.log.2011-11-23-00_00.1.3.gz
-rw-r--r-- 1 root root        33 2011-11-26 06:49 access.log.2011-11-23-00_00.2.gz.3.gz
-rw-r--r-- 1 root root  44590255 2011-11-25 18:59 access.log.2011-11-25-00_00.4.gz
-rw-r--r-- 1 root root        20 2011-11-25 06:42 access.log.2011-11-23-00_00.1.4.gz
-rw-r--r-- 1 root root        20 2011-11-25 06:42 access.log.2011-11-24-00_00.4.gz
-rw-r--r-- 1 root root        20 2011-11-25 06:42 access.log.2011-11-21-00_00.1.4.gz
-rw-r--r-- 1 root root        33 2011-11-25 06:42 access.log.2011-11-21-00_00.2.gz.4.gz
-rw-r--r-- 1 root root        20 2011-11-25 06:42 access.log.2011-11-22-00_00.1.4.gz
-rw-r--r-- 1 root root        33 2011-11-25 06:42 access.log.2011-11-22-00_00.2.gz.4.gz

What I want is to have a new file generated everyday and have the previous days file gzip'd. How should I setup my logrotate to do that?

1 Answer 1

1

This line:

/var/log/apache2/access.log.* 

matches all files in the /var/log/apache2 directory, so includes all gzipped files already present. It is basically compressing the files already compressed.

Change it to

/var/log/apache2/access.log

to make sure it only acts on the access.log file. Other than that, the settings are right.

3
  • The only issue with that is I'm adding a time/date stamp to the filename in the CustomLog line. So I guess changing the CustomLog line to use access.<datetime_stamp>.log would be better so I could use /access.*.log
    – rforte
    Nov 29, 2011 at 23:30
  • Aah, yes I see. Yeah, you need to exclude the .gz files somehow. Changing the timestamp position in the filename would be the simplest way.
    – Paul
    Nov 29, 2011 at 23:45
  • marking this answer more or less correct since updating the filename does the trick.
    – rforte
    Nov 30, 2011 at 4:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .