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.
for f in *-access.log.gz
# Test to see if the main backup directory exists if not then create it
if [ ! -d $HomeDir/$BackupDir ]; then
# Test to see if the backup directory for the year exists, if not then create it.
if [ ! -d $HomeDir/$BackupDir/$BackupYear ]; then
# Test to see if the backup directory for the month exists, if not then create it.
if [ ! -d $HomeDir/$BackupDir/$BackupYear/$BackupMonth ]; then
#Step #02 - command to be executed:
cp ~/log/*-access.log.gz ~/$BackupDir/$BackupYear/$BackupMonth/
# end of script
More details at MrCompTech.com