Rsync Sync Two Directories

Posted onby

How to sync the data between two servers without using SAN replication ? Do you have better than RSYNC tool for this job ? I don’t think so, you we will not get better than RSYNC. It uses ‘rsync algorithm’ which provides a very fast method for syncing the directories or filesystems. An important feature of rsync is that the mirroring takes place with only one transmission in each direction and which is not available in other similar programs.

To sync files between two local directories on Unix or Linux, you can either choose to perform a soft link to the source directory or use rsync or lsyncd. A guide explaining how to sync two FreeNAS datasets on different devices with rsync. I would like to do a two-way automatic sync between folders Directory A andDirectory B.This means that whenever a file in Directory A or one of its sub-directories is changed, that change is immediately applied to Directory B, and whenever a file in Directory B or one of its sub-directories is changed, that change is immediately applied to Directory A. Keep the contents of two directories in sync with SyncFolders by Ashwin on October 09, 2020 in Software, Windows software - Last Update: October 14, 2020 - 11 comments If you constantly transfer files to and from computer to a USB Flash drive, external storage or a remote location, you may know that it can be a boring task.

Rsync’s default port is 873 and its an opensource software. Rsync is available for Unix,Linux and windows operating systems. You can freely download rsync source code from rsync.samba web portal.
Here we will see how to sync data between two servers using automated script.
Operating system:Red Hat Linux

Rsync Sync Two Directories Free


Rsync Sync Two Folder

Source Server IP: (mylinz1)
Source Server Path:/db/oracle/

Destination Server IP: (mylinz2)
Destination Server Path:/db/oracle-bck/
Before proceeding to rsync part,you need to configure key-less authentication to ensure each can communicate using that.

1.Verify whether your host will allow to perform RSA key-less authentication.If you didn’t get similar output,then you need to comment out the lines in sshd_config.

2.Generate the keygen if you didn’t have one already. Here the user is “root”.

3.Share the “” file across the servers to enable the ssh key-less authentication.

4.Verify your work.

Let’s move to RSYNC part.


Rsync Sync Two Directories

Here is the rsync script which will be used for syncing the data between servers mylinz1 & mylinz2.

Here I am running script from mylinz1 to sync the data.

This script creates log as well with newly synchronized files information.

Testing rsync script:

1.Run the script manually.

2.Verify the log file.

Rsync Sync Two Directories

3.Create a new file to sync the data to mylinz2 server.

4.Verify the whether the newly created file synced in mylinz2.
That’s it. Our rsync script is working fine.

If you want to sync the data between two servers automatically on preferred time interval,you can add the script in to crontab.

Add the below line in root’s crontab to sync the data for every 5 minutes.

Thank you for reading this article.Please leave a comment if you have any doubt.