Saturday, July 19, 2014

Rsync backup over SSH

Rsync

Backup is the one of the major task in the IT administration. There are so many tools  are there both in open source and proprietary.Rsync is one of the best tool which we can use in Linux. This can be used for taking backup in local system as well as in remote Linux system.

Rsync is using synchronization mechanism for copying the files from source to location. The main advantage of it is it can copy the delta changes so that we can reduce the time of copying entire content again.

For example, if we need to take a backup of an application server and which is running currently. So mostly we will stop the application serverto get proper backup and will copy the content to backup location. But if the size of the directory is very big the time to copy the entire content will take time so the larger will be the down time. here we can use rsync with out stopping the application server initially. How it is, do the rsync of the directory first with out stopping application server. Once it is done most of the files will be copied to the destination. Then stop the application server and do one more rsync with same . This will only cope the delta files so the time for copying will be very less. So you can start the application in short down time.

Example:

rsync -avz --delete source/ destination/

Here is one script for Rsync from  remote server to local server over ssh.


REMOTE_USER=root
REMOTE_HOST=192.168.5.
REMOTE_PATH=/var/lib/mysql
LOCAL_PATH=/backup1/
KEY_FILE=mykey
COMMAND=`which ssh`
echo $COMMAND
 
 rsync  --delete -avvvz  -e "$COMMAND -i $KEY_FILE" $REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH  $LOCAL_PATH



No comments:

Post a Comment

Which operating system you like most?