我希望 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/