Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"

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

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

Thanks all!

share|improve this question

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


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.