Apache Rotate Logs and Log Rotate

Matthew Seaman m.seaman at infracaninophile.co.uk
Thu Feb 15 09:17:07 UTC 2007

Peter Pluta wrote:
> I have Apache making separate log files for each of my virtual hosts and
> putting them in /home/vhostname/log. Rotate logs makes a new log every
> 24 hours, but the logs quickly add up and since the sites are fairly
> busy the logs are at times over 5gigs. Is there any way to make rotate
> logs delete the log files after two days? Someone recommended me Log
> Rotate (from the ports tree), but this program does basically what
> Rotate logs does; except it makes things more complicated because it
> needs to restart apache and such. Is there a easy way to just have
> Apache's rotatelogs rotate the logs and then delete them after two days?
> Any feedback, suggestions, or comments would be greatly appreciated.

rotatelogs doesn't do any sort of deletion stuff.  It just doesn't have
that capability.

On the other hand a simple cronjob that deletes all but the N newest files
in the directory is just a small matter of scripting.  Assuming you want
to keep at least 30 of the latest log files, you can generate a list of
files to delete by something like:

	ls -1t /home/vhostname/log.* | sed -n -e '30,$p'

Alternatively you can abuse the daily_clean_tmps periodic job to delete
any files from that directory over a certain age.



Dr Matthew J Seaman MA, D.Phil.                       Flat 3
                                                      7 Priory Courtyard
PGP: http://www.infracaninophile.co.uk/pgpkey         Ramsgate
                                                      Kent, CT11 9PW, UK

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 250 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20070215/d4849d35/signature.pgp

More information about the freebsd-questions mailing list