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.
mv access_log ./bak/`date +%Y-%m-%d`_access_log
The first line (briefly) 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.
I originally wrote this one to archive out my DHCP logs. With modification, this script can be used with cron to backup or archive any files to any location on an automatic basis.