Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!
#!/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---------- >>$LOG
echo This log started on `date +%H`:`date +%M`:`date +%S` >>$LOG
echo ----------LOG START---------- >>$LOG
echo >>$LOG
#Set the current time
STARTHOUR=10#`date +%H`
STARTMIN=10#`date +%M`
STARTSEC=10#`date +%S`
#============================================================================#
#Check drive mounts
#============================================================================#
#Test to see if the drive is mounted and available
#To add a drive, simply create a new line with an incremented variable
#If a drive is not mounted, exit for data safety reasons
MOUNT[0]=/mnt/hitachi
MOUNT[1]=/mnt/green
#Get the number of variables in the array
n=${#MOUNT
[*]}
#Loop through each drive mapping
for ((i=0;i<n;i++)); do
if [ `mount | grep -c "${MOUNT[i]}"` -eq "1" ]; then
echo "${MOUNT[i]} is mounted." >>$LOG
else
echo "WARNING: ${MOUNT[i]} is not mapped." >>$LOG
echo "If this path is incorrect, please correct it." >>$LOG
echo "Script is stopping to prevent damage." >>$LOG
echo >>$LOG
exit 2
fi
done
echo "All drives are mounted correctly." >>$LOG
echo >>$LOG
#============================================================================#
#End drive check
#============================================================================#
#============================================================================#
#This section is the daily rsync section
#============================================================================#
#Set the locations
COREY=/mnt/hitachi/rsync/corey/
COREY_COPYTO=/mnt/green/rsync_copy/corey
#Copy the files
rsync -av --delete $COREY $COREY_COPYTO >>$LOG
#============================================================================#
#End daily rsync section
#============================================================================#
#============================================================================#
#This is the archive function, runs on Monday only
#============================================================================#
echo >>$LOG
echo ----------------------------- >>$LOG
echo Weekly archive start >>$LOG
echo ----------------------------- >>$LOG
echo >>$LOG
if [ `date +%u` -eq "1" ]; then
echo Starting weekly archive >>$LOG
#Set the backup source locations
COREY1="/mnt/hitachi/rsync/corey/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"
#Tar the files
tar -cf "$COREY1_GZIP" "$COREY1" >>$LOG
#Copy the files to the green drive
cp "$COREY1_GZIP" "$COREY2_GZIP" >>$LOG
echo Weekly archive complete! >>$LOG
else
echo Weekly archive is not set to run today >>$LOG
fi
echo >>$LOG
echo ----------------------------- >>$LOG
echo Weekly archive end >>$LOG
echo ----------------------------- >>$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 >>$LOG
echo -----------LOG END----------- >>$LOG
echo This log ended on `date +%H`:`date +%M`:`date +%S` >>$LOG
echo Runtime: "$HOUR"h "$MIN"m "$SEC"s >>$LOG
echo -----------LOG END----------- >>$LOG
exit
----------LOG START----------
This log started on 14:47:04
----------LOG START----------
/mnt/hitachi is mounted.
/mnt/green is mounted.
All drives are mounted correctly.
building file list ... done
sent 2985514 bytes received 20 bytes 1194213.60 bytes/sec
total size is 178450622473 speedup is 59771.76
-----------------------------
Weekly archive start
-----------------------------
Weekly archive is not set to run today
-----------------------------
Weekly archive end
-----------------------------
-----------LOG END-----------
This log ended on 14:47:06
Runtime: 0h 0m 2s
-----------LOG END-----------
----------LOG START----------
This log started on 14:59:27
----------LOG START----------
/mnt/hitachi is mounted.
/mnt/green is mounted.
WARNING: /mnt/ohgod is not mapped.
If this path is incorrect, please correct it.
Script is stopping to prevent damage.
Or SATA cards that use PCIe, which is the preferred method.
If I fire up 3 VM's at once, music/video will sometimes skip; this is unacceptable and poor planning on my part.