Logrotation 帮助

Logrotation 帮助

我有如下的自定义日志轮换。

cat /etc/logrotate.d/apache
#
#
/var/log/apache/apache.log
{
        daily
        rotate 30
        size 1G
        compress
        missingok
        copytruncate
dateformat -%Y-%m-%d-%s.log
}

这是 ls 输出。

ls -lrth /var/log/apache/apache.log*
-rw------- 1 root root 171M Oct 10 02:01 apache.log-2023-10-10-1696883462.log.gz
-rw------- 1 root root 121M Oct 10 05:01 apache.log-2023-10-10-1696894261.log.gz
-rw------- 1 root root 119M Oct 10 09:01 apache.log-2023-10-10-1696908661.log.gz
-rw------- 1 root root 143M Oct 10 13:01 apache.log-2023-10-10-1696923061.log.gz
-rw------- 1 root root 136M Oct 10 16:01 apache.log-2023-10-10-1696933861.log.gz
-rw------- 1 root root 132M Oct 10 19:01 apache.log-2023-10-10-1696944661.log.gz
-rw------- 1 root root 132M Oct 10 22:01 apache.log-2023-10-10-1696955461.log.gz
-rw------- 1 root root 161M Oct 11 02:01 apache.log-2023-10-11-1696969861.log.gz
-rw------- 1 root root 145M Oct 11 06:01 apache.log-2023-10-11-1696984261.log.gz
-rw------- 1 root root 137M Oct 11 11:01 apache.log-2023-10-11-1697002261.log.gz
-rw------- 1 root root 120M Oct 11 13:01 apache.log-2023-10-11-1697009461.log.gz
-rw------- 1 root root 118M Oct 11 15:01 apache.log-2023-10-11-1697016661.log.gz
-rw------- 1 root root 134M Oct 11 19:01 apache.log-2023-10-11-1697031061.log.gz
-rw------- 1 root root 967M Oct 11 20:52 apache.log

所以这就是问题所在。我在轮换日志文件中看到 10 月 10 日的日志apache.log-2023-10-11-1696969861.log.gz,在 中看到 10 月 9 日的日志apache.log-2023-10-10-1696883462.log.gz。我不希望发生这种情况。我希望 10 月 10 日的日志只在 apache.log-2023-10-10-***********.log.gz 中。你们能指导一下如何实现吗?

相关内容