#!/bin/bash # This script is designed to make daily backups of important files. # Designed correctly it will make a backup of the files and then they will be # available for download to a backup machine. Hopefully this will rotate the # the daily logs and I will have seven mostly current backups. #Set the daily extension extension=`date +%A` lockfile=/var/backup/$extension.logs #Name the different backups daily=/var/backup/daily.$extension.tar.bz2 current=/var/backup/current.tar current_config=/var/backup/current_config.tar current_logs=/var/backup/current_logs.tar.bz2 current_web=/var/backup/current_web.tar.bz2 #Setup the types of backups www=/var/www named=/var/named etc=/etc mail=/var/spool/mqueue mail1=/var/spool/mail home=/home sucks_logs=/home/elgreen/logs all_logs=/var/log mysql=/var/lib/mysql exclude=/etc/cron.backup/ex_file all="$mail $mail1 $home $mysql" logs="$all_logs" configs="$etc $named" #Changed this from ext3 to just a regular mount to see if the mount problem will go away #mount -t ext3 -o rw /dev/hdb7 /var/backup touch $lockfile #Move the config backup if it's there if [ -f $current_config ]; then bzip2 $current_config mv -f $current_config.bz2 $current_config.bz2.1 # tar -cf $current_config $configs # else fi tar -cf $current_config $configs #fi #Create the log backups if they don't exist, otherwise, update the backup if [ -f $current_logs ]; then echo "Moving $current_logs to $current_logs.1" # bzip2 $current_logs mv -f $current_logs $current_logs.1 echo "Creating new log file" tar -cjf $current_logs $logs #if [ -f !$current_logs ]; then # echo "Creating new log file" # tar -cf $current_logs $logs else echo "Log file missing- creating new" tar -cjf $current_logs $logs fi if [ -f !$current_web ]; then tar -cjf $current_web -X $exclude $www else mv -f $current_web $current_web.1 tar -cjf $current_web -X $exclude $www fi # Rotate logs if they exist- this should give me a total of 14 days backup- # if it works if [ -f $daily ]; then mv -f $daily $daily.1 fi #create the tar file tar -cjf $daily -X $exclude $all #Rotate the current tar file- should give me two running backups if [ -f $current ]; then mv -f $current $current.1 fi #Create a tar file that should always be the current one... tar -cf $current -X $exclude $all rm -rf $lockfile #umount /var/backup exit 0