Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to schedule logs rotate with these rules:

  1. log files for the last 2 day are kept untouched
  2. 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.)
  3. 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!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

According to @koniu from superuser, it is not possible. As far as I checked, I didn't find any other ways for that.

For the age of the log, you have a maxage directive which according to the manpage:

   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.

Looks like it doesn't work on old logs moved in olddir.

share|improve this answer
    
Thanks for the link. It covers the question about olddir. It's a bit tricky, but it should work! It was really helpful. Am I right, that logrotate can not delete old logs from olddir? Should my solution in postrotate work? –  user148378 Dec 5 '12 at 13:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.