Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

it's possible to configure logrotate to create an olddir per day?

I'd like to get the same bash result, like this:

user@blade1022m:~$ date "+%y%m%d"
120208

In /etc/logrotate.conf (pseudo-code):

/home/mhd-01/logs/*.log {
  daily
  missingok
  rotate 62
  olddir /home/mhd-01/logs/archive/${`date "+%y%m%d"`}/
  postrotate
     /etc/init.d/apache2 restart
}

Thanks all!

share|improve this question

1 Answer 1

It's not possible without hacking logrotate.

However, you can 'cheat' and achieve the same effect using a symlink and cron. In your logrotate.conf set olddir to /home/mhd-01/logs/olddir/ and create a daily cronjob that does:

mkdir /home/mhd-01/logs/archive/$(date "+%y%m%d")
ln -sf /home/mhd-01/logs/archive/$(date "+%y%m%d") /home/mhd-01/logs/olddir/

Make sure this new cronjob runs before the logrotate job - either stick it in /etc/cron.daily/ with a number in the front (eg. 01_linkrotate) or set it to run at midnight (00:00)


A cruder variant of this solution, without symlinks, would use cron to move the contents of olddir to the archive. The cronjob, running after logrotate or at the end of the day (23:59), would do the following:

mkdir /home/mhd-01/logs/archive/$(date "+%y%m%d")
mv /home/mhd-01/logs/olddir/* /home/mhd-01/logs/archive/$(date "+%y%m%d")/
share|improve this answer

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.