I want to schedule logs rotate with these rules:
- log files for the last 2 day are kept untouched
- log files older than 2 days are archived and moved to folder named by date, they were created. (For ex. All logs for 01 Dec 2012 are moved to 20121201 and archived.)
- log files older than 14 days are removed.
I want to use logrotate for this, but I'm not sure it suits my needs or not.
I'd like something like this, but it doesn't work.
/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 does not understand that $DIR is variable.
Any suggestions are welcome!