Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Tips/Tricks/Mods

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 8th December 2011, 20:33
MrCompTech MrCompTech is offline
Member
 
Join Date: Jul 2010
Posts: 92
Thanks: 1
Thanked 19 Times in 8 Posts
 
Default How To Setup A Cron Job to Copy Previous Month Apache Log Files To A Backup Directory

ISPConfig3 & FC13 - How To Setup A Cron Job to Copy Previous Month Apache Log Files To A Backup Directory

Desired goal: to maintain an ongoing archive of the http access log files. The standard log file rotation only keeps the last 30 days as part of the log rotation process, log files older than this are deleted. This came about as I wanted to be able to perform offline analysis of the log files after the month had ended, but found out that if I didn't manually move the backup files (*.gz) on the first or second of the month then they would start getting deleted.

Script:
#!/bin/bash
BackupDir=logbackup
cd ~/log
for f in *-access.log.gz
do
filename=$f
done
cd ~
HomeDir=$PWD
BackupYear=${f:0:4}
BackupMonth=${f:4:2}

# Test to see if the main backup directory exists if not then create it
if [ ! -d $HomeDir/$BackupDir ]; then
mkdir $HomeDir/$BackupDir
fi

# Test to see if the backup directory for the year exists, if not then create it.
if [ ! -d $HomeDir/$BackupDir/$BackupYear ]; then
mkdir $HomeDir/$BackupDir/$BackupYear
fi

# Test to see if the backup directory for the month exists, if not then create it.
if [ ! -d $HomeDir/$BackupDir/$BackupYear/$BackupMonth ]; then
mkdir $HomeDir/$BackupDir/$BackupYear/$BackupMonth
fi

#Step #02 - command to be executed:
cp ~/log/*-access.log.gz ~/$BackupDir/$BackupYear/$BackupMonth/

# end of script

More details at MrCompTech.com
__________________
MrCompTech.com
Reply With Quote
The Following 4 Users Say Thank You to MrCompTech For This Useful Post:
falko (9th December 2011), nokia80 (9th December 2011), nveid (9th December 2011), till (13th December 2011)
Sponsored Links
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[ISPconfig Install] Cannot allocate memory Cordoban Installation/Configuration 3 25th August 2006 13:20
Problems with Apache and Updating Jubalint Installation/Configuration 2 21st May 2006 19:50
error compiling php5 florianrieder Installation/Configuration 3 23rd March 2006 18:41
setup fails on debian 3.1 dtrumbower Installation/Configuration 7 7th March 2006 13:42
ISP install problems Debian sarge 3.1 lerra Installation/Configuration 1 5th January 2006 16:37


All times are GMT +2. The time now is 09:38.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.