How to mirror a folder among 2 servers

Hi, in this post I'll show you how to mirror ,synchronize a folder from serverA to serverB with rsync for a backup purpose or what ever you want and need.

First we have to install rsync on both machines for RedHat/Fedora/CentOS you would use:
# yum install rsync
for Debian systems:
# apt-get install rsync
or if you work with SuSE use: yast


Now we need to create a user that will be used by rsync on both servers:
# useradd -d /home/syncuser -m -s /bin/bash syncuser
and give this user a password:
# passwd syncuser


The next step is to make sure that serverA can log into serverB without password so we could create a crontab script which do the synchronization automatic without human interaction.
for this step please go read my post - how to ssh without password

After we test we can ssh from serverA to serverB without password, we can test the rsync,
make sure you have a folder on serverB that you want to backup all your data to and run the next command on serverA:
# rsync -raz --progress --size-only --delete /DirOnServerA/* syncuser@serverB:/DirOnServerB


Now go the serverB and check if you data are there.

All you left to do is to to add the rsync script to crontab and you can sleep well at night.




.

No comments:

Post a Comment