Tuesday, January 27, 2015

How to create a rsync auto backup script with email notification







Step 1 :- First enable a password less SSH to the remote server from you backup PC

Step 2 :- Then copy and paste the below code in to a text file and save as a .sh file


#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin

#### Mail server Data Backup ####
#### Created by Vipin Chereekandy ####
#### chereekandy@gmail.com ####

## Below command will sync the data with the Backup server ###
rsync -avgr -e ssh --delete root@192.168.1.1:/home/data /secondary_bkp/mailserver/.

## Below command will send you an email notification ##
if [ $? != "0" ]
  then
   echo Mail server data Backup is failure|mail -s "Mail server Backup Failure" yourid@example.com
  else
   echo Mail server data Backup is successful|mail -s "Mail server Backup Successful" yourid@example.com
 fi

### End of the script ##


Note : Replace IP address, mail ID and directory path with your own Server base.


Step 3 :- Set a cronjob to run this script



**** Thanks ****





No comments:

Post a Comment