Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Script to backup data to a remote Server  (Read 4088 times)

0 Members and 1 Guest are viewing this topic.

lijeshk

  • Guest
Script to backup data to a remote Server
« on: October 25, 2013, 08:31:30 pm »
First of all you would need to enable ssh key authentication for enabling the password less access. Copy the public key of the source machine to the authorized_keys of the backup machine.  Hope you know how to enable the SSH key authentication. Then execute this script as a cronjob.

---
#!/bin/bash -eu

#### Backup Server IP ###

BKP_SRV=”xxx.xxx.xxx.xxx″

### User name for rsync ###

USER=”root”

### Directories
BACKUPDIR1=”/var/www”
BACKUPDIR2=”/var/lib/mysql”

### Destination Directory##

DSTDIR=”/backup/”

### This line is for checking the backup server is up or not if its not up it will send a mail to the e-mail id specified###

EMAIL=”user@example.com“

VAR=`ping -s 1 -c 1 $BKP_SRV > /dev/null; echo $?`

if [ $VAR -eq 0 ];then

rsync -av –delete $BACKUPDIR1 $USER@$BKP_SRV:$DSTDIR > /root/log/1.txt

rsync -av $BACKUPDIR2 $USER@$BKP_SRV:$DSTDIR > /root/log/2.txt

echo “Backup procedure completed successfully.”| mail -s “Backup Completed”$EMAIL

else

echo “Cannot connect to $BKP_SRV.” | mail -s “$BKP_SRV is down” $EMAIL

fi

---