logrotate甚至空文件

时间:2016-10-06 18:53:10

标签: cron logrotate

我在cron作业中运行logrotate时出现问题:尺寸太小的文件无法轮换。

我希望所有文件,甚至是那些size = 0的文件都可以旋转。 这是我的配置

/logs/server-*.log {
    rotate 1
    missingok
    compress
    sharedscripts
    copytruncate
    dateext
    dateformat %Y-%m-%d-%s
    lastaction
        # scripts to move *.gz files here
    endscript
}

请指教。 我正在运行Ubuntu 14.04服务器

1 个答案:

答案 0 :(得分:0)

据我所知,您现在要使用的是默认的Logrotate行为。但是,您可以显式添加ifempty配置:

/logs/server-*.log {

    # Rotate the log file even if it is empty, 
    # overriding the notifempty option (ifempty is the default).
    ifempty

    rotate 1
    missingok
    compress
    sharedscripts
    copytruncate
    dateext
    dateformat %Y-%m-%d-%s
    lastaction
    # scripts to move *.gz files here
    endscript
}
相关问题