Saturday, May 22, 2010

Reset runtime Apache access.log & error.log

Hi Friends,

Today morning i got a page from our data center that one of the Production Apache based Webserver diskspace was almost full & most of the space was consumed by access.log & error.log!

Well, i knew this would happen some day since it has been a year we put these machines in Production, moreover we havent setup the log rotation for access.log & error.log.

Now, i had two tasks at my hand...
1) Take a quick backup of both the log files.
2) Reset/Clear the logs to size zero without bouncing the Apache Webserver services, i.e. at Runtime.

Solution:
1) Took a zipped backup on another disk in the same machine:
bash$ zip /d01/Apache_BK/access_log_20052010.zip access.log
bash$ zip /d01/Apache_BK/error_log_20052010.zip error.log

2) Reset/Clear the logs to size zero using /dev/null:
bash$ cp /dev/null access.log
bash$ cp /dev/null error.log

OR

bash$ cat /dev/null > access.log
bash$ cat /dev/null > error.log

Well, using /dev/null is very effective on Linux & Unix platforms, but if you are wondering if we have something similar to that in Windows, then the answer is yes!

C:\>type NUL > access.log
C:\>type NUL > error.log

Just hope that Windows havent locked the log file with an exclusive handle ;-)
If you have a lock on the file & need to reset the log file without restarting the Apache services, then your only option is to install Unlocker (http://ccollomb.free.fr/unlocker/)

Hope this tip helps as no one wants to bounce a Production system just for taking a log backup & resetting its size to zero :-D

Enjoy!

Keywords:
Oracle HTTP Server, Apache, OHS, /dev/null, NUL, access.log, error.log, zip, backup, etc

1 comment:

Khiswar said...

Thanks, glad I found your site. Really helpful.