我想logrotate复制并截断日志文件,并在不同的物理磁盘上使用olddir.根据手册,olddir不能在不同的物理磁盘上,因为logrotate的默认行为是仅重命名原始日志文件,这对于不同的物理磁盘是不可能的.
好吧,但我正在使用copytruncate指令,它生成原始文件的副本,然后截断原始文件.因此,将新复制的文件移动到不同物理磁盘上的不同位置应该没有问题.
但是当我运行logrotate时,它仍然会抱怨logfile和olddir在不同设备上运行.
它有什么办法吗?可能运行一些自定义的postrotate脚本,将日志文件移动到所需的位置?
Shu*_*ngi 16
这是来自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.
Run Code Online (Sandbox Code Playgroud)
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
}
Run Code Online (Sandbox Code Playgroud)