0

I have this config for nginx logrotate

/var/log/nginx/*.log {
        daily
        missingok
        rotate 3
        compress
        delaycompress
        notifempty
        create 0640 www-data adm
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi \
        endscript
        postrotate
                invoke-rc.d nginx rotate >/dev/null 2>&1
        endscript
}

Ideally, it should compress file in gz and then remove the previous files after 3 days but here are my log files

-rw-r--r-- 1 www-data www-data 1.4G Dec 10 00:00 2016-12-09-access.log.1
-rw-r----- 1 www-data adm         0 Dec 11 06:33 2016-12-10-access.log
-rw-r--r-- 1 www-data www-data 1.5G Dec 11 00:00 2016-12-10-access.log.1
-rw-r----- 1 www-data adm         0 Dec 12 06:30 2016-12-11-access.log
-rw-r--r-- 1 www-data www-data 1.6G Dec 12 00:00 2016-12-11-access.log.1
-rw-r----- 1 www-data adm         0 Dec 13 06:46 2016-12-12-access.log
-rw-r--r-- 1 www-data www-data 1.4G Dec 13 00:00 2016-12-12-access.log.1
-rw-r----- 1 www-data adm         0 Dec 14 06:25 2016-12-13-access.log
-rw-r--r-- 1 www-data www-data 1.4G Dec 14 00:00 2016-12-13-access.log.1
-rw-r----- 1 www-data adm         0 Dec 15 06:50 2016-12-14-access.log
-rw-r--r-- 1 www-data www-data 1.5G Dec 15 00:00 2016-12-14-access.log.1
-rw-r--r-- 1 www-data www-data 362M Dec 15 07:59 2016-12-15-access.log
-rw-r----- 1 www-data adm         0 Dec 15 06:50 ---access.log
-rw-r----- 1 www-data adm       254 Dec 15 04:53 ---access.log.1
-rw-r----- 1 www-data adm       202 Oct 25 03:58 ---access.log.10.gz
-rw-r----- 1 www-data adm       578 Oct 24 02:30 ---access.log.11.gz
-rw-r----- 1 www-data adm      1.3K Oct 23 06:11 ---access.log.12.gz
-rw-r----- 1 www-data adm       980 Oct 22 05:39 ---access.log.13.gz
-rw-r----- 1 www-data adm       648 Oct 21 05:59 ---access.log.14.gz
-rw-r----- 1 www-data adm      1006 Oct 20 05:45 ---access.log.15.gz
-rw-r----- 1 www-data adm       150 Dec 13 23:03 ---access.log.2.gz
-rw-r----- 1 www-data adm        89 Dec 13 05:46 ---access.log.3.gz
-rw-r----- 1 www-data adm       421 Dec 12 06:23 ---access.log.4.gz
-rw-r----- 1 www-data adm       277 Nov  8 17:16 ---access.log.5.gz
-rw-r----- 1 www-data adm       174 Nov  7 05:52 ---access.log.6.gz
-rw-r----- 1 www-data adm       104 Nov  5 18:42 ---access.log.7.gz
-rw-r----- 1 www-data adm       111 Nov  4 23:43 ---access.log.8.gz
-rw-r----- 1 www-data adm       220 Oct 25 19:36 ---access.log.9.gz

And logrotate status is

"/var/log/nginx/2016-12-01-access.log" 2016-12-2
"/var/log/nginx/2016-11-21-access.log" 2016-11-22
"/var/log/nginx/2016-09-16-access.log" 2016-9-17
"/var/log/mail.err" 2016-2-10
"/var/log/nginx/2016-10-06-access.log" 2016-10-7
"/var/log/nginx/2016-09-14-access.log" 2016-9-15
"/var/log/nginx/2016-11-02-access.log" 2016-11-3
"/var/log/nginx/2016-10-04-access.log" 2016-10-5
"/var/log/nginx/2016-10-22-access.log" 2016-10-23
"/var/log/nginx/2016-09-30-access.log" 2016-10-1
"/var/log/landscape/package-reporter.log" 2016-12-15
"/var/log/nginx/2016-10-20-access.log" 2016-10-21

Which doesn't give too much info regarding the recent days rotation.How can I debug the configuration ?

1 Answer 1

1

You can debug particular script with -df parameter:

logrotate -df /etc/logrotate.d/nginx

and execute it immediately (if you need it):

logrotate -f /etc/logrotate.d/nginx

Note that there are often settings in the /etc/logrotate.conf file that apply to all logrotate scripts, so it may be necessary to run it in conjunction with your specific script:

logrotate /etc/logrotate.conf /etc/logrotate.d/nginx

However this config file usually calls ALL scripts under the logrotate.d folder, so you may want to comment this line out temporarily, or create a copy of this file for testing which excludes the directory call:

#include /etc/logrotate.d

Also read about delaycompress configuration option in the man:

Postpone compression of the previous log file to the next rotation cycle. This has only effect when used in combination with compress. It can be used when some program can not be told to close its logfile and thus might continue writing to the previous log file for some time.

3
  • ran the -df, go chopapp.com/#7og0bsf . It is not considering access.log.1 files for deletion.
    – hemc4
    Commented Dec 29, 2016 at 10:40
  • There is no access.log.1 in your ls listing. Debug ran properly, I dont see any problems. Try dateext directive with your logrotate config and remove date prefixes from log files names (like 2016-12-09-). Commented Dec 29, 2016 at 19:27
  • I mean not considering date-access.log.1 files for deletion as you shaw in te logs
    – hemc4
    Commented Dec 30, 2016 at 8:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.