Subversion Log Rotation


The Apache rotatelogs program supports automatically starting a new log file whenever the current log file reaches a certain size or has had records written to it for a certain period of time. However, the rotatelogs program, rotatelogs.exe, as implemented in

rotatelogs logfile [ rotationtime [ offset ]] | [ filesizeM ]

In your subversion installation, you have to edit the httpd.conf file to set the right configuration. Ex: /etc/opt/CollabNet_Subversion/conf/httpd.conf

 sudo vi /etc/opt/CollabNet_Subversion/conf/httpd.conf

Create the following entries:

ErrorLog "|/opt/CollabNet_Subversion/bin/rotatelogs  /var/opt/CollabNet_Subversion/logs/error_log.%c  86400 -300"
CustomLog "|/opt/CollabNet_Subversion/bin/rotatelogs /var/opt/CollabNet_Subversion/logs/access_log.%c 86400 -300" common

Make sure to comment the existing entries related to error and access logs.

# ErrorLog var/opt/CollabNet_Subversion/logs/error_log

# CustomLog var/opt/CollabNet_Subversion/logs/access_log common

After saving the httpd.conf, Stop and Start the Subversion:

sudo /opt/CollabNet_Subversion/bin/apachectl -k stop
sudo /opt/CollabNet_Subversion/bin/apachectl -k start

How it works?

ErrorLog “|/opt/CollabNet_Subversion/bin/rotatelogs  /var/opt/CollabNet_Subversion/logs/error_log.%c  86400 -300″

CustomLog “|/opt/CollabNet_Subversion/bin/rotatelogs /var/opt/CollabNet_Subversion/logs/access_log.%c 86400 -300″ common

These parameters specify that rotatelogs, when writing the log file for error and access records will:

•  Place the file in the logs folder, and give it a file name starting with Error_ – the rest of the file name contains a date stamp

•  Check whether to create a new log file every 24 hour (86400 seconds)

•  Use a 5-hour offset from the GMT (-300 minutes)

Whenever the rotatelogs program checks whether to start a new log file (Every 24 hours in the case above) it also checks every log file in the log file directory, created by that rotatelogs process, create and modify timestamps are older than the retention period.

The rotatelogs process for error and access logging will not delete any access log files, or vice versa. The % symbols in the log file name direct the rotatelogs program to treat them as strftime substitution characters. In the case of error log files, the file name Error_%c.log causes rotatelogs to create a file with the date and time stamp.

For the list of all ‘%’ symbols that you can use in the file name, and their meanings, see: http://httpd.apache.org/docs-2.0/programs/rotatelogs.html

Apache, does not support automatic cleanup of old log files – the administrator has to delete old log files to prevent the disk from filling up.

Add the below line in cron tab so that log files will be removed if they are  more than 5 days old.

export EDITOR=vi
sudo crontab -e
30     1     *     *     * find /var/opt/CollabNet_Subversion/logs/ -type f -mtime +5 -exec rm {} ;

Save the crontab.

Your Subversion installation is ready to rotate logs.