Skip to content
Indus LeveL
unison synchronization rsync ssh linux sysadmin automation

Bi-Directional File Synchronization Across Linux Data Centers Using Unison

A production systems automation guide on establishing bi-directional file synchronization between distributed server endpoints using Unison and secure SSH tunnels.

2 min read
Cover illustration representing active bi-directional file synchronization and Unison file tracking across enterprise server farms

Replicating application configuration directories, web assets, or database backup archives across distributed production environments (such as active failover sites in east-dc1 or west-dc1) is a fundamental operations task. While standard utilities like rsync excel at one-way mirror operations, they lack native conflict resolution and state tracking for active bi-directional modifications across twin server directories.

In this systems automation guide, I explore deploying Unison, an advanced file synchronization utility designed to compare local and remote file tree hash representations, safely reconcile bi-directional structural changes, and automate batch sync executions over secure SSH tunnels.

Step 1: Installing Unison Core RPM Binaries

Deploy the compiled Unison utility package onto target local and remote execution servers.

# Install Unison core packages from distribution mirrors
rpm -ivh /root/unison-2.40.63-1.el5.rf.i386.rpm

Step 2: Running Batch Unison Remote Synchronizations

Unlike traditional copy commands, Unison utilizes persistent index structures to maintain active state snapshots of synchronized directories. When executing automated cron tasks or background daemons, running Unison in silent batch mode ensures background processing without interactive user prompts.

1. Initiating the Bi-Directional Batch Command

Sync local folder path /sync_dir/ against remote target host 192.168.56.103 using SSH remote access protocols:

unison -batch -confirmbigdel=false /sync_dir/ ssh://192.168.56.103//sync_dir/

2. Breakdown of Parameter Execution Logic

Understanding the operational impact of Unison flag parameters is critical to preventing accidental production file corruption:

  • -batch: Instructs Unison to bypass all interactive validation prompts. If a file has been modified simultaneously on both endpoints and enters an irreconcilable merge state, Unison cleanly skips the conflicting resource without halting the broader synchronization execution block.
  • -confirmbigdel=false: Instructs Unison not to prompt for user approval when deleting large portions of a directory hierarchy, enabling seamless automated garbage collection across sync nodes.
  • ssh://host//path: Employs native SSH underlying execution protocols, ensuring zero cleartext packet transmissions across external network boundaries.

Step 3: Integrating Advanced SSH Custom Tuning

When running high-frequency Unison sync daemons across high-latency WAN networks, tuning underlying SSH transfer layers prevents connection drops and transport hangs.

Create a dedicated Unison execution profile (~/.unison/default.prf) containing optimized SSH keep-alive instructions:

# default.prf
root = /sync_dir/
root = ssh://user@192.168.56.103//sync_dir/

# Enforce batch execution rules
batch = true
confirmbigdel = false

# Custom SSH wrapper settings
servercmd = ~/bin/unison
sshargs = -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -o compression=yes

References

Back to Blog
Share:

Follow along

Stay in the loop — new articles, thoughts, and updates.