/var/log/apache2/access.log を /var/log/apache2 に書き込まれる他のすべてのログ ファイルとは別に処理するように logrotate を構成したいと考えています。他のすべてのログを名前で明示的に指定せずに、これを機能させる方法はありますか?
logrotate が glob を使用してファイル名をパターン マッチングすることをオンラインで読みましたが、正しいパターンを記述できないようです。私は多くのパターンを試しましたが、それらはすべて次のエラーでした:
considering log /var/log/apache2/!(access.log)
log /var/log/apache2/!(access.log) does not exist -- skipping
上記のパターンは bash でも機能しますが、shopt -s extglob
. logrotate を使ってこれを行う方法はありますか?
ローテーションしようとしたときに失敗する prerotate スクリプトを使用して、これを機能させようとしましたaccess.log
が、logrotate は、access.log を 2 回ローテーションしようとしていると不平を言います。
error: /etc/logrotate.d/apache2:16 duplicate log entry for /var/log/apache2/access.log
これは私が得た最も近いものです:
# rotate access.log every time logrotate is called
/var/log/apache2/access.log {
missingok
rotate 168
compress
create 640 root adm
# rotate the log every time we call logrotate (size 0)
size 0
dateext
dateformat .%Y%m%d.%s
copytruncate
}
# rotate everything daily EXCEPT access.log
/var/log/apache2/*.log {
daily
missingok
rotate 7
compress
create 640 root adm
copytruncate
# filter out access.log, which we want to rotate on its own schedule above
nosharedscripts
prerotate
bash -c "[[ ! '$1' =~ /access.log ]]"
endscript
}