-1

I have the following configuration for logrotating the app logs.

/opt/tomcat/logs/app-web.txt {
    copytruncate
    daily
    size 500M
    compress
    delaycompress
    rotate 0
    missingok
    notifempty
}

/opt/tomcat/logs has a lot of files


app-web.txt
app-web.txt.1
app-web.txt.2
app-web.txt.3
app-web.txt.4
..
..
..
..
..
app-web.txt.100

I have placed the configuration inside /etc/logrotate.d/app-web. I am running CentOs 6.6

I want to have 9 files only like aap-web.txt and app-web.txt.1.gz to app-web.txt.9.gz

Each file inside /opt/tomcat/logs are of 498 M of size. and they are created every 1 hour 30 min.

 $cat /var/lib/logrotate.status 

displays the time that I ran manually. It doesn't run automatically by cron.

Vikash
  • 141
  • 3

1 Answers1

2
rotate 0

from the man page

rotate count Log files are rotated count times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather than rotated.

You probably want

rotate 9

As to why you are seeing all the other files, my guess is that they are old (check the date/time) and logrotate is not considering them because they do not match the name app-web.txt. I would just archive those I needed for the relevant period and then delete them. I would then expect logrotate to start managing the files as expected.

Note that generally cron is configured to run logrotate just once per day ( /etc/cron.dailylogrotate). If you want to rotate the files based on size and that size is reached more frequently than once a day you will need to run logrotate more frequently.

user9517
  • 114,104
  • 20
  • 206
  • 289