Log File Archive Script Andrew Mallett | Revised September 2013

Log files contain a huge amount of valuable information about system activity, but over time can become unwieldly as their size grows. Some applications will auto-archive their logs. This script copies the day's Apache logs to a subdirectory and renames them based on the date..

/usr/local/apache/bin/apachectl stop

cd /usr/local/apache/logs

mv access_log ./bak/`date +%Y-%m-%d`_access_log

touch access_log

/usr/local/apache/bin/apachectl start

The first line stops the Apache Web service..

The script then changes to the directory containing the Apache logs.

The access_log is moved to the previously created bak directory and renamed based on the date, which looks something like 2010-05-01_access_log

A new access_log is created in the current directory using the touch command..

And the Apache Web server daemon is restarted. In reality this all happens within the blink of an eye.

This apachelogbak.sh runs from a cron job every night at 2359..

59 23 * * * /sc/apache/apachelogbak.sh >/dev/null

..so make sure full paths to all files are used in the script.

With modification, this script can be used with cron to backup or archive any files to any location on an automatic basis.


More custom scripts at Shell-scripts.com

Comments (0)

E-mail (Will not appear online)
;-) :-) :-D :-( :-o :-O B-) :oops: :-[] :-P
To prevent automated Bots form spamming, please enter the text you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
This comment form is powered by GentleSource Comment Script. It can be included in PHP or HTML files and allows visitors to leave comments on the website.

Disposable Email   Throwaway Email   Throwaway Email