How to Automatically Sync Upload Folders Across Multiple Servers with Lsyncd

Lsyncd (Live Syncing Daemon) is a lightweight Linux tool that automatically mirrors files across multiple servers in real time. It watches a folder for changes and instantly syncs only the new or modified files to other servers using efficient rsync over SSH. This makes it perfect for multi-server environments—such as load-balanced web servers—where upload folders, images, or media need to stay identical on all machines without manual syncing or heavy distributed file systems.

Lsyncd = Live Sync Daemon
It watches a folder in real-time and syncs only new/changed files to other servers.

How It Works

  • You run Lsyncd ONLY on Server 1
  • It watches /path/to/upload
  • Whenever a new file appears → instantly rsync to Server2 & Server3
  • Sends only the changed file, not the entire directory
  • Uses SSH (secure)
  • No downtime
  • Very light

Step 1 — Install on Server 1

sudo apt update
sudo apt install lsyncd -y

Step 2 — Set up SSH key (passwordless) to Server 2 & 3

ssh-keygen -t ed25519
ssh-copy-id root@SERVER2_IP
ssh-copy-id root@SERVER3_IP

Step 3 — Create config /etc/lsyncd/lsyncd.conf.lua

settings {
    logfile    = "/var/log/lsyncd.log",
    statusFile = "/var/log/lsyncd-status.log",
    inotifyMode = "CloseWrite",
}

sync {
    default.rsync,
    source = "/var/www/upload",
    target = "root@SERVER2_IP:/var/www/upload",
    rsync = {
        archive = true,
        compress = true,
        _extra = {"--ignore-existing"}
    }
}

sync {
    default.rsync,
    source = "/var/www/upload",
    target = "root@SERVER3_IP:/var/www/upload",
    rsync = {
        archive = true,
        compress = true,
        _extra = {"--ignore-existing"}
    }
}

Step 4 — Start Lsyncd

sudo systemctl restart lsyncd
sudo systemctl enable lsyncd

Now Server2 and Server3 will mirror new uploads instantly.