我需要設置logrotate來從運行在服務器上的應用程序中旋轉日誌文件。 我需要文件名中的日期。如何使用logrotate在文件名中插入日期
我設置了dateext和dateformat來在日期中添加一個 - 。 結果文件名是:whatever.csv_2012-03-03
我希望時間戳是文件名的一部分,以確保擴展的安全; Whatever_2012-03-03.csv。
# Daily rotation
daily
# We keep original file live
copytruncate
# Rotation is 1 so we have always .1 as extension
rotate 1
# If file is missing keep working
missingok
sharedscripts
postrotate
day=$(date +%Y-%m-%d)
mv blabla.csv.1 /var/www/gamelogs/dir/blabla$day.csv
endscript
}
這是簡單而正常工作:
我喜歡這個解決方案。如果我理解正確,它有一個副作用:logrotate不再限制保存文件的數量。如果有意的話,那很好。 – Marian 2014-07-08 06:59:17
很容易在你的postrotate腳本中添加一個'find $ logdir -mtime + $ maxage -delete'語句。 – Rob 2014-08-07 09:07:06
@Rob,那麼,實際使用logrotate有什麼意義呢? – cnst 2014-09-15 20:27:53