[英]How to force (or workaround) logrotate to move old logs to olddir on different physical disk?
我希望logrotate
復制和截斷日志文件並在不同的物理磁盤上使用 olddir。 根據手冊,olddir 不能在不同的物理磁盤上,因為 logrotate 的默認行為是只重命名原始日志文件,這在不同的物理磁盤上是不可能的。
好吧,但我正在使用copytruncate
指令,它制作原始文件的副本,然后截斷原始文件。 因此,將新復制的文件移動到不同物理磁盤上的不同位置應該沒有問題。
但是當我運行 logrotate 時,它仍然抱怨不同設備上的 logfile 和 olddir beeing。
有什么辦法可以解決嗎? 可能運行一些自定義 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
}
現在有屬性copy
, copytruncate
和copyrename
可以與olddir
結合使用,將文件移動到單獨的設備。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.