Offsite Backup Script Linux

Offsite Backup Script Linux
For those of us in the 21st century using disk based backup, we still need to backup to some sort of remote media to keep at a secure offsite location
so basically we have our Backup server that all servers backup to on disk, from there we need to have a script to copy all data to the remote media. There are a few prerequisites:
1) Sendmail/Postfix must relay mail
2) your create /media/Offsite folder to mount your Media
3) you have mounted your /dev/sdb or /dev/sdc to /media/Offiste (mount /dev/sdc /media/Offsite)
4) You have edited the Source Paths for your Environment
5) You understand that Backups are YOUR RESPONSIBILITY and that by using this script you acknowledge that we take ZERO RESPONSIBILITY for data loss, and that  isentirely YOUR PROBLEM if something goes wrong.
Here it is:
#!/bin/sh
# Created By Zwiegnet Linux Admins 5/24/2013
# Version 1.1
#############
# Variables #
#############
DAY=`date +%F`
LOGDIR=/var/log/OffsiteBackup
echo Offsite Backup Program 2013
########################################################
# Check If Mount Point is Available, if not Cancel Job #
########################################################
if grep -qs ‘/media/Offsite’ /proc/mounts; then
     echo “Mount Point Detected Successfully!”    
     echo “Starting Backup Now, This Will Take a While, Please Wait……..”
else
    echo “/media/Offsite is NOT mounted!”
    echo “Job Terminated, Please mount /media/Offsite, Goof”
    exit 0
fi
###################################
# Copy New Data to /media/Offsite #
###################################
rsync -avzW –partial –delete –force –exclude lost+found /Source/Directory /media/Offsite | tee /$LOGDIR/$DAY.txt
rsync -avzW –partial –delete –force –exclude lost+found /Source/Directory /media/Offsite | tee /$LOGDIR/$DAY.txt
rsynv -avzW –partial –delete –force –exclude lost+found /Source/Directory /media/Offsite | tee /$LOGDIR/$DAY.txt
rsync -avzW –partial –delete –force –exclude lost+found /Source/Directory /media/Offsite | tee /$LOGDIR/$DAY.txt
####################################################
# Change Permissions to make ALL Readable/Writable #
####################################################
echo Setting Permissions…..
chmod 777 -R /media/Offsite/*
##############################################
# Display Disk Space In Event Log Afterwards #
##############################################
echo Writing Disk Space to Event Log…..
df -h | awk ‘/sdc/ {print “Drive SDC “$5″ Used for Offsite Backups”}’ >> $LOGDIR/$DAY
#Remove Disk
umount -l /media/Offsite
# Send An Email that the Backup is Done
echo Sending Completion Email
# Create/Send Email 
SUBJECT=”Offsite Backup Completed!”
EMAIL=”user@yourdomain.com”
# Email body
EMAILMESSAGE=”/tmp/messagebody.txt”
echo “Offsite Backup Has Been Completed” > $EMAILMESSAGE
echo “Please Remove and Move to a Secured Location” >> $EMAILMESSAGE
# send message using /bin/mail
/bin/mail -s “$SUBJECT” “$EMAIL” < $EMAILMESSAGE
echo Offsite Backup Complete!!!!
exit 0
That’s it!
Offsite Backup Script Linux Offsite Backup Script Linux Reviewed by Unknown on 6:03 AM Rating: 5

No comments:

Powered by Blogger.