我想通过 捕获慢速查询logrotate
,并且我希望它们每周轮换一次,并且我想节省一年的价值。日志采用以下形式:
-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
因为日志最终被如此频繁地写入,我如何确保没有遗漏任何内容logrotate
?该过程本身不会创建文件,它需要有原始文件。我在想这会做到这一点:
/var/log/mysqld*-slow.log {
missingok
notifempty
weekly
rotate 52
compress
delaycompress
create 0644 mysql root
}
所以它应该压缩旧的,并使用正确的权限创建相同的文件名,但我不确定 logrotate 如何处理在移动中写入的内容。
看来该
copytruncate
功能可以做到这一点: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.
我已经把它放在了地方。