Logrotate is a tool is a tool installed by default on linux distributions. It rotates logs automatically but it also compresses or transfers its. It could also suppress obsoletes files.

It main config file is:


If we want to add log files to be rotate automatically by logrotate, we must type some lines of configuration at the end of that file. Or if you want a clean configuration, you can make your own config file and add an include in the main config file of logrotate.You must know that secondary configuration file parameters supplant parameters of the main configuration file. It’s the same thing for parameters at the end of a configuration file which supplant parameters specified at the beginning of this file.


Here it’s a simple configuration of the log rotation of access.log for a website:

/home/www/siteinternet.com/logs/access.log {
    rotate 7
                              /usr/bin/killall -HUP apache2

rotate 7 : It will rotate log on 8 files (7 log + the current one)
daily : the rotation is done everyday
missingok : if a log file is missing, it continues with the next one without errors
notifempty : If there is no data in a log file, no rotate job for this one
postrotate /usr/bin/killall -HUP apache2: it kills orphan processes of Apache


If we want to have automatic rotation on all .log files of a specific folder, rather than doing a configuration file for each .log file, we can easily do that in one configuration. We must type as an absolute path: /home/www/siteinternet.com/logs/*.log

System tools of Linux already use logrotate for rotating their logs. They have their configurations in /etc/logrotate.d/ . This path is included in the main config file of logrotate.

root@serveur01:/# cd /etc/logrotate.d/
root@serveur01:/etc/logrotate.d# ls -al
total 48
drwxr-xr-x  2 root root 4096 15 déc.  11:48 .
drwxr-xr-x 94 root root 4096 16 déc.  22:51 ..
-rw-r--r--  1 root root  114 22 mars   2012 apache2
-rw-r--r--  1 root root  233 25 janv.  2012 apt
-rw-r--r--  1 root root   59 19 oct.   2012 aptitude
-rw-r--r--  1 root root  232 30 janv.  2012 dpkg
-rw-r--r--  1 root root  146 31 janv.  2012 exim4-base
-rw-r--r--  1 root root  126 31 janv.  2012 exim4-paniclog
-rw-r--r--  1 root root 1004  8 mars   2012 pure-ftpd-common
-rw-r--r--  1 root root  315  9 juin   2012 rsyslog
-rw-r--r--  1 root root  382  9 mars   2012 samba
-rw-r--r--  1 root root  251 13 janv.  2013 zabbix-agent



We can force the execution of logrotate with the following command:

serveur5.openlog.it:/# logrotate -f /etc/logrotate.conf


If you have the following error message when logrotate is executing (forced or not):

serveur5.openlog.it:/# logrotate -f /etc/logrotate.conf
error: /etc/logrotate.conf:25 duplicate log entry for /home/www/siteinternet.com/logs/access.log

In fact, it indicates that there is several configuration files which do a rotation on the same log file. So, we must comment or delete one of the configurations for avoiding these kind of conflict.

Man of logrotate (english) : http://linux.die.net/man/8/logrotate

Leave a Reply

Your email address will not be published. Required fields are marked *