Linux Local and Remote backup using rsync and rdiff

Scenario : –

1)      Take daily backup of linux server to local backup disk/secondary drive

2)      Copy the backup drive to the remote server.

( Using this method we can keep our data in 3 different places )

Setup Local Backup

1)      create a folder /backup

2)      rsync the necessary files to /backup

rsync -avzub /boot/   /backup/boot

rsync -avzub /usr/local/scripts/   /backup/User_local_scripts

rsync -avpuzb  –exclude ‘logs’ –copy-links –exclude ‘logs’  –exclude ‘*.tar’  –exclude ‘*.gz’ –exclude ‘*.zip’ –exclude ‘*.sql’ –exclude ‘log’  /usr/local/apache/htdocs    /backup/apache_htdocs

Copy the local backup to Remote server

Now all the necessary files are copied to /backup.  We need to copy this to a remote backup server for data redundancy .

I found Rdiff is a nice backup tool for copying folders overs a network.

Rdiff-backup:- is a very nice backup tool.We can copy one directory to another ,possibly over a network.The target directory ends up a copy of the source directory, but extra reverse diffs are stored in a special subdirectory of that target directory, so you can still recover files lost some time ago. The idea is to combine the best features of a mirror and an incremental backup. rdiff-backup also preserves subdirectories, hard links, dev files, permissions, uid/gid ownership, modification times, extended attributes, acls, and resource forks. Also, rdiff-backup can operate in a bandwidth efficient manner over a pipe, like rsync. Thus you can use rdiff-backup and ssh to securely back a hard drive up to a remote location, and only the differences will be transmitted. Finally, rdiff-backup is easy to use

1) Download rdiff  and install rdiff

yum install rdiff-backup ( easiest method )

Or you can download the tar and Install

Wget http://savannah.nongnu.org/download/rdiff-backup/rdiff-backup-1.2.8.tar.gz

2) tar –zxf rdiff-backup-1.2.8.tar.gz

3) cd rdiff-backup

4) ./configure

5) make

6) make install

7) Create a script to copy the directory to remote server.

vi  rdiff-backupTo-Remote.sh

#!/bin/bash

# hostname adminlogs.info

# this will copy the /backup folder to remoteserver /backup location

rdiff-backup /backup  remoteserverIP::/backup/adminlogs  > /dev/null 2>&1

8)  add this script to cron  ( execute the cron at 1:30 am  )

30  01 * * * bash  rdiff-backupTo-Remote.sh

NB :- You should allow password less login from the local server to remote server.

You can use the following  url to create the ssh password less login

http://adminlogs.info/2011/05/27/passwordless-login-ssh/

That’s it…You have successfully configured your backup script. You can relax , your data is safe and available in 3 disks 😉