需要 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.gz10 月 9 日日志我不想apache.log-2023-10-10-1696883462.log.gz发生这样的事。我希望10 月 10 日日志只在同一天日志轮换文件中,而不改变上述格式。例如 apache.log-2023-10-10-***********.log.gz。你们能指导一下如何实现吗?

相关内容