Synchronize Files between PCs and Servers

Introduction

This tutorial teaches you how to automate the synchronization of two or more folders on different PCs or servers on the same network.

Buckle up!

1. Static IP Address

The first step is to set a static IP address on e…


This content originally appeared on DEV Community and was authored by Amjad Abujamous

Introduction

This tutorial teaches you how to automate the synchronization of two or more folders on different PCs or servers on the same network.

Buckle up!

1. Static IP Address

The first step is to set a static IP address on each of the devices in the network.

2. Setup ssh keys on both devices

Open up a terminal or WSL on windows and type in the following:

ssh-keygen -t rsa
ssh-copy-id 192.168.1.15

where 192.168.1.15 is the IP address of the secondary (or replica) server.

3. Install Unison

The file synchronization tool

Unison is a reliable file synchronization tool designed to be cross platform, fast, and efficient. One can install it via the releases page in their github repository.

Note that the tool must exist on all PCs that need to synchronize their folders.

4. Configure Unison

Folders and parameters

Configuring Unison is quite easy since it has a built-in GUI. Also, the configuration only needs to be done on the "primary" machine, and the others will periodically (or almost instantly) receive replicas of the files in a specific folder.

4.1 Extract Unison Archive

Extract the archive which has unison in it to your desired folder. In my case, it is ~/Tools/Unison.

Unison Folder

4.2 Launch Unison GUI

Navigate to the bin folder and execute the file unison-gui.

Unison GUI file

Unison GUI

4.3 Create a profile

A Unison profile specifies how the synchronization process will take place and which folders on which machines will be synchronized. To create one, click on "Add" and follow the Profile creation wizard.

Profile creation wizard

Profile Description:

  • Profile name: default
  • Description: Default profile

Connection Setup:

  • Synchronization kind: using ssh
  • Host: 192.168.1.15
  • User: remote_user (replaced by your username on the secondary device)
  • Enable compression: true

Directory selection:

  • Local Directory: Documents
  • Remote Directory: /home/remote_user/Documents

Specific Options:

  • [Unchecked] Synchronization invloving a FAT partition.

Done.

4.4 Configure the profile

Select default and click on "Edit" in the GUI.

Edit default profile

Add the following options by click on "Add", selecting the option, and then applying the value.

  • auto: true
  • batch: true
  • sshcmd: /home/remote_user/Tools/Unison/bin/unison (replace with the executable location on the remote/secondary machine)

4.5 Run unison

You can either run unison using the UI by selecting the profile and click on Open which will run the tool or by navigating to the executable location and typing

./unison default.prf

That's it! Now the contents of the folder on the first machine should be mirrored on the second one. Note that the profile name would be different in case you'd want to run another.

5. Automate Unison

On the Linux bash, Mac Terminal, and WSL, one can automate the command and run it at a certain interval. On Ubuntu, for instance, the command below after navigting to the unison executables folder will do the trick.

while true; do ./unison default.prf; sleep 10 done 

Where 10 is the number of seconds.

More on bash automation and sh files here.

Conclusion

Congratulations! You made it to the end of this tutorial. Hope this tutorial enabled you to do file synchronization seamlessly.

Cover image credit.


This content originally appeared on DEV Community and was authored by Amjad Abujamous


Print Share Comment Cite Upload Translate Updates
APA

Amjad Abujamous | Sciencx (2024-09-08T18:17:47+00:00) Synchronize Files between PCs and Servers. Retrieved from https://www.scien.cx/2024/09/08/synchronize-files-between-pcs-and-servers/

MLA
" » Synchronize Files between PCs and Servers." Amjad Abujamous | Sciencx - Sunday September 8, 2024, https://www.scien.cx/2024/09/08/synchronize-files-between-pcs-and-servers/
HARVARD
Amjad Abujamous | Sciencx Sunday September 8, 2024 » Synchronize Files between PCs and Servers., viewed ,<https://www.scien.cx/2024/09/08/synchronize-files-between-pcs-and-servers/>
VANCOUVER
Amjad Abujamous | Sciencx - » Synchronize Files between PCs and Servers. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/08/synchronize-files-between-pcs-and-servers/
CHICAGO
" » Synchronize Files between PCs and Servers." Amjad Abujamous | Sciencx - Accessed . https://www.scien.cx/2024/09/08/synchronize-files-between-pcs-and-servers/
IEEE
" » Synchronize Files between PCs and Servers." Amjad Abujamous | Sciencx [Online]. Available: https://www.scien.cx/2024/09/08/synchronize-files-between-pcs-and-servers/. [Accessed: ]
rf:citation
» Synchronize Files between PCs and Servers | Amjad Abujamous | Sciencx | https://www.scien.cx/2024/09/08/synchronize-files-between-pcs-and-servers/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.