Advance

How To Synchronize Files Between Two Servers On Debian 10 With Unison

How To Synchronize Files Between Two Servers On Debian 10 With Unison
0
(0)

Unison is a file-synchronization software that is designed for OSX, Unix such as Solaris, Linux, OS X, and windows similar to rsync. With this tool, your file and folders are always up to date on an interconnected system. You can Unison is free and full source code is available under the General Public License. Unison is used to store two replicas of a collection of files and directories on different hosts, modified separately, and then brought up to date by propagating the changes in each replica to the other. It can also be stored on different disks on the same host. In this tutorial, you will learn How To Synchronize Files Between Two Servers On Debian 10 With Unison. If you are preparing to buy a new Linux VPS what you need as quickly as you could imagine.

Recommended Article: Tutorial Installing Email Server on Debian 10 with ISPconfig

To let this tutorial work better, please consider the below Prerequisites:

A non-root user with sudo privileges.

Run the Unison as the root user.

To set up, follow our Initial Setup with Debian 10.

Tutorial Files Synchronization Between Two Servers On Debian 10 With Unison

Join us with this article to learn setting up file synchronization between two Debian servers with Unison. You will see that files changed on server 1 will be replicated to server2 and vice versa. Unison would not act similar to simple mirroring or backup tools and is capable to deal with updates to both replicas of a distributed directory structure. You will need to use two Debian servers and synchronize the directory /var/www between the two servers. Let’s go through the steps of this guide to learn and finish it.

How to install Unison

You should install Unison on server 1 and server 2. You are connecting from server 1 to server 2 via SSH, so the SSH packages are required. To edit the files, you can install and use nano as the file editor on the shell. Let’s get started:

apt-get -y install unison openssh-server ssh nano

How to create a private/public key pair on server 1

Run the following command to create a private/public key pair on server1.example.com and just hint Enter when you are asked.

ssh-keygen -t dsa

Then, copy your public key to server2.example.com

ssh-copy-id -i $HOME/.ssh/id_dsa.pub [email protected]
# ssh-copy-id -i $HOME/.ssh/id_dsa.pub [email protected]

Next., check if the public key of server 1 is correctly transferred to server 2 or not:

cat $HOME/.ssh/authorized_keys

How to run Unison

At this point, you can run Unison for the first time to synchronize the /var/www directory on both servers. Run the following command on server 1:

Note: Since this is the first Unison running, you will have to answer some questions.

unison /var/www ssh://192.168.0.101//var/www

To ensure the synchronization of server 1 and server 2, check the /var/www directory on them. While you do not wish to run Unison interactively, create a preferences file like /root/.unison/default.prf. that contains all settings that you will have to specify on the command line:

nano /root/.unison/default.prf

Not just for the directives of the path, commands should make the file self-explaining. But if you have not specified path directives, the directories in the root directives would be synchronized. If you specify path directives, the paths are relative to the root path and results to synchronize only these subdirectories, not the whole directory specified in the root directive. have a look at Unison’s mn page to learn more about the available options.

man unison

Since you have put all settings in a preferences file, you are ready to run Unison without any arguments:

unison
Recommended Article: How To Synchronize Files Between Two Servers On Debian 10 With Unison

How to create a corn job for Unison

In this step, you need to create a corn job for Unison on server1.example.com to automate the synchronization.

crontab -e

The following command Unison would run every 5 minutes. Also, you can adjust it to your needs.

man 5 crontab

You can use the full path to unison here (/usr/bin/unison) to ensure that cron knows where to find unison. However, your unison location may be different. So, to see where yours is, type:

which unison

How to test Unison

T check if the setup is fully working or not, test the two-way synchronization of Unison. To create a test file with the content ”Test 1”, use the command below on server 1:

echo "Test 1" > /var/www/test.txt

Then, wait for 5 minutes. To show the content of the file test.txt on the screen, run the following command on server 2:

cat /var/www/test.txt

Now, to update the content of your test file to ”Test 2”, use the command below on server 2:

echo "Test 2" > /var/www/test.txt

Again, you should wait about 5 minutes and then run the following command on server 2:

cat /var/www/test.txt

 

That’s that. It was all you need to be able to set up the Unison file synchronization between two servers on Debian 10.

 

Conclusion

In this article, you learned How To Synchronize Files Between Two Servers On Debian 10 With Unison. IPFs, FreeFileSync, and Syncthing are the tools that are alternatives for Unison. It will provide you some features like configuration management packages, distributed filesystem, uni-directional mirroring utilities.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

View More Posts
Marilyn Bisson
Content Writer
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day