MySQL doesn’t logs error to new file after rotating?

In the postrotate, I redirect both stderr and stdout to a log file to see what happens: postrotate /usr/bin/mysqladmin flush-logs > /var/log/mysqladmin.flush-logs 2>&1 endscript What I get is: /usr/bin/mysqladmin: connect to server at ‘localhost’ failed error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’ It sounds like mysqladmin doesn’t read /root/.my.cnf during logrotate. So, try … Read more

How can I rotate many log files into a different subdirectory per rotation?

You should be able to call an external script in the postrotate directive: postrotate /path/to/your.sh endscript and have that script do the moving, e.g.: #!/bin/bash newdir=/var/log/example/`date +%Y%m%d` mkdir $newdir mv /var/log/example.1.gz $newdir find /var/log/example -mindepth 1 -maxdepth 1 -mtime +7 \ -type d -print0 | xargs -0 rm -rf However, it might be easier to … Read more

Why is logrotate causing Apache to seg fault each time?

It seems that if I just change the logrotate script to be a single block, i.e. /var/log/apache2/*.log, /srv/apache/logs/*.log {….} I don’t get the segfault. So it was just the two blocks were causing a second restart attempt during the first restart… If I enter apache2ctl graceful & apache2ctl graceful & apache2ctl graceful & apache2ctl graceful … Read more

logrotate does not compress /var/log/messages

Adding delaycompress to the configuration section for /var/log/messages solved the problem. From man logrotate: delaycompress Postpone compression of the previous log file to the next rota‐ tion cycle. This only has effect when used in combination with compress. It can be used when some program cannot be told to close its logfile and thus might … Read more

How to specify exceptions from wildcard settings in a logrotate configuration file?

The most elegant answer is to put thatonespecial.log in a separate directory so it wouldn’t be able to match the wildcard. If that won’t work, then you can use globs to narrow down your wildcard. It’s messy, but if you absolutely can’t move the file location then it’s probably your only real option. Something like … Read more

Delete files with logrotate

In that case you may want to use postrotate. In the example below postrotate will delete files that are older that 1 day after logs been rotated, feel free to modify it to fit your needs. /opt/log/app/app.log.* { missingok nomail postrotate /usr/bin/find /opt/log/app/ -name “app.log.*” -type f -mtime +0 -exec rm {} \; endscript }