linux - 如何强制(或解决方法)logrotate 将旧日志移动到不同物理磁盘上的 olddir?

标签 linux logrotate

我希望 logrotate 复制和截断日志文件并在不同的物理磁盘上使用 olddir。根据手册,olddir 不能在不同的物理磁盘上,因为 logrotate 的默认行为是只重命名原始日志文件,这在不同的物理磁盘上是不可能的。

好吧,但我正在使用 copytruncate 指令,它会制作原始文件的副本,然后截断原始文件。因此,将新复制的文件移动到不同物理磁盘上的不同位置应该没有问题。

但是当我运行 logrotate 时,它​​仍然提示 logfile 和 olddir 在不同的设备上发出蜂鸣声。

有什么办法吗?可能运行一些自定义 postrotate 脚本,将日志文件移动到所需位置?

最佳答案

这是来自 logrotate 手册页。

  olddir directory <br>
        Logs  are moved into directory for rotation. **The directory must be on the 
        same physical device as the log file being rotated**, and is assumed to  be 
        relative  to  the  directory holding the log file unless an absolute path 
        name is specified. When this option is used all old versions of  the  log 
        end  up  in  directory.   This  option  may be overridden by the noolddir 
        option.

在同一物理设备上存在 olddir 是一种限制。

可以使用以下解决方法。

olddir设置为同一物理磁盘的目录,并使用postrotate脚本将olddir的内容移动到不同的目录物理设备。

logrotate 配置文件示例:

/var/log/httpd/*log {
        copytruncate
        olddir /var/log/httpd/olddir
        rotate 5
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        mv /var/log/httpd/olddir/* /vagrant/httpd/olddir/
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}

关于linux - 如何强制(或解决方法)logrotate 将旧日志移动到不同物理磁盘上的 olddir?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36235042/

相关文章:

linux - 将 grep 结果放入变量中

linux - 无法使用 apktool 重新编译 apk 文件

Redis logrotate配置

Tomcat:log4j 不旋转日志文件

linux - 将模式的奇数和偶数出现替换为另一个相同的模式

linux - 没有 www 的虚拟主机 2 重定向到虚拟主机 1

c - 如何找到哪个线程被卡住了

linux - 如何仅根据文件大小进行 logrotate?

ubuntu - 错误 : error creating state file/var/lib/logrotate/status: Permission denied

CentOS 中的 Logrotate,maxsize 选项