0

I want to capture slow queries via logrotate, and I want them to rotate weekly and I want to save a year's worth. The logs take the form:

-rw-r-----. 1 mysql  root           1239 Feb 21 18:46 mysqld1-slow.log
-rw-r-----. 1 mysql  root            885 Feb 11 14:48 mysqld2-slow.log
-rw-r-----. 1 mysql  root            885 Feb 22 08:58 mysqld3-slow.log
-rw-rw-rw-. 1 mysql  root            802 Feb 11 14:47 mysqld-slow.log

Because the logs end up being written to so frequently, how can I make sure nothing is missed by logrotate? The process itself doesn't create the file, it needs to have the original there. I was thinking this would do it:

/var/log/mysqld*-slow.log {
    missingok
    notifempty
    weekly
    rotate 52
    compress
    delaycompress
    create 0644 mysql root
}

So it should compress the old, and create the same filename with the right permissions, but I'm unsure how logrotate handles something that's written to amidst the movement.

0

It would appear the copytruncate function can accomplish this:

copytruncate Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one. It can be used when some program cannot be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.

I have put this in place.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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