#!/bin/bash
#This script contains all of the rsync commands that are run daily on
#Thideras' file server. The main use for this script is to backup to
#alternate locations, such as an external drive or remote location.
LOG=/mnt/hitachi/logs/rsync/rsync-$(date +%m-%d-%Y).log
#Give the date and time started
echo ----------LOG START---------- 1>>$LOG
echo This log started on `date +%H`:`date +%M`:`date +%S` 1>>$LOG
echo ----------LOG START---------- 1>>$LOG
echo 1>>$LOG
#Set the current time
STARTHOUR=10#`date +%H`
STARTMIN=10#`date +%M`
STARTSEC=10#`date +%S`
#============================================================================#
#This section is the daily rsync section
#============================================================================#
[COLOR=Lime]#Test to see if the drive is mapped and available
if [ `mount | grep -c "/mnt/hitachi"` -eq "1" ]; then
#If it is mounted, continue[/COLOR]
#Set the locations
COREY=/mnt/hitachi/rsync/corey/
COREY_COPYTO=/mnt/green/rsync_copy/corey
DAN=/mnt/hitachi/rsync/dan/
DAN_COPYTO=/mnt/green/rsync_copy/dan
DIANA=/mnt/hitachi/rsync/diana/
DIANA_COPYTO=/mnt/green/rsync_copy/diana
#Copy the files
rsync -av --delete $COREY $COREY_COPYTO 1>>$LOG
rsync -av --delete $DAN $DAN_COPYTO 1>>$LOG
rsync -av --delete $DIANA $DIANA_COPYTO 1>>$LOG
[COLOR=Lime] else
#If it is not mounted, skip the section
echo WARNING! The mount point "/mnt/hitachi" is NOT MOUNTED! 1>>$LOG
echo Skipping RSYNC portion of this script! 1>>$LOG
echo Please verify that the drive is mounted properly. 1>>$LOG
fi[/COLOR]
#============================================================================#
#End daily rsync section
#============================================================================#
#============================================================================#
#This is the archive function, runs on Monday only
#============================================================================#
echo 1>>$LOG
echo ----------------------------- 1>>$LOG
echo Weekly archive start 1>>$LOG
echo ----------------------------- 1>>$LOG
echo 1>>$LOG
[COLOR=Lime]if [ `mount | grep -c "/mnt/hitachi"` -eq "1" ] && [ `mount | grep -c "/mnt/green"` -eq "1" ]; then[/COLOR]
if [ `date +%u` -eq "1" ]; then
echo Starting weekly archive 1>>$LOG
#Set the backup source locations
COREY1="/mnt/hitachi/rsync/corey/World of Warcraft"
DAN1="/mnt/hitachi/rsync/dan/World of Warcraft"
DIANA1="/mnt/hitachi/rsync/diana/World of Warcraft"
#Set the backup destination locations
COREY1_GZIP="/mnt/hitachi/backups/Corey_WoW/WoW-$(date +%m-%d-%Y).tar"
COREY2_GZIP="/mnt/green/backups/corey/WoW-$(date +%m-%d-%Y).tar"
DAN1_GZIP="/mnt/hitachi/backups/Dan_WoW/WoW-$(date +%m-%d-%Y).tar"
DAN2_GZIP="/mnt/green/backups/dan/WoW-$(date +%m-%d-%Y).tar"
DIANA1_GZIP="/mnt/hitachi/backups/Diana_WoW/WoW-$(date +%m-%d-%Y).tar"
DIANA2_GZIP="/mnt/green/backups/diana/WoW-$(date +%m-%d-%Y).tar"
#Tar and Gzip the files
tar -cf "$COREY1_GZIP" "$COREY1"
tar -cf "$DAN1_GZIP" "$DAN1"
tar -cf "$DIANA1_GZIP" "$DIANA1"
#Copy the files to the green drive
cp "$COREY1_GZIP" "$COREY2_GZIP" 1>>$LOG
cp "$DAN1_GZIP" "$DAN2_GZIP" 1>>$LOG
cp "$DIANA1_GZIP" "$DIANA2_GZIP" 1>>$LOG
echo Weekly archive complete! 1>>$LOG
else
echo Weekly archive is not set to run today 1>>$LOG
fi
else
#If it is not mounted, skip the section
[COLOR=Lime] echo WARNING! The following mount points may NOT be mounted: 1>>$LOG
echo /mnt/hitachi 1>>$LOG
echo /mnt/green 1>>$LOG
echo Skipping archive portion of this script! 1>>$LOG
echo Please verify that the drives are mounted properly. 1>>$LOG
fi[/COLOR]
echo 1>>$LOG
echo ----------------------------- 1>>$LOG
echo Weekly archive end 1>>$LOG
echo ----------------------------- 1>>$LOG
#============================================================================#
#End weekly archive
#============================================================================#
#Get the current time in minutes and seconds, assign to variables
ENDHOUR=10#`date +%H`
ENDMIN=10#`date +%M`
ENDSEC=10#`date +%S`
#Compute the difference between the start and end time
HOUR=$(($ENDHOUR - $STARTHOUR))
MIN=$(($ENDMIN - $STARTMIN))
SEC=$(($ENDSEC - $STARTSEC))
#If the time goes under 0, correct the time
if [ $SEC -lt "0" ]
then
SEC=$(($SEC + 60))
MIN=$(($MIN - 1))
fi
if [ $MIN -lt "0" ]
then
MIN=$(($MIN + 60))
HOUR=$(($HOUR - 1))
fi
if [ $HOUR -lt "0" ]
then
HOUR=$(($HOUR + 24))
fi
#Add the end date and time
echo 1>>$LOG
echo -----------LOG END----------- 1>>$LOG
echo This log ended on `date +%H`:`date +%M`:`date +%S` 1>>$LOG
echo Runtime: "$HOUR"h "$MIN"m "$SEC"s 1>>$LOG
echo -----------LOG END----------- 1>>$LOG
exit