3

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!

Fabio
  • 31

1 Answers1

2

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")/
koniu
  • 616