我想按照以下规则安排日志轮换:
我想为此使用logrotate,但是我不确定它是否适合我的需求。
我想要这样的东西,但它不起作用。
/mylog/* { prerotate DIR=$(date +%y%m%d); // actually it's current date mkdir $DIR endscript daily rotate 2 olddir /mylog/$DIR missingok compress postrotate find /mylog -type d -mtime +180 | xargs rm -f endscript }
Logrotate不理解$ DIR是可变的。
任何build议,欢迎!
根据超级用户的@ koniu, 这是不可能的 。 据我检查,我没有find任何其他的方式。
对于日志的年龄,你有一个maxage指令,根据手册:
maxage count Remove rotated logs older than <count> days. The age is only checked if the logfile is to be rotated. The files are mailed to the configured address if maillast and mail are configured.
看起来它不适用于在olddir中移动的旧日志。