What is the Difference Between rsync and lsync?

rsync is one of the most powerful tools for syncing files and directories between systems. It’s fast, versatile, and can even copy over SSH with minimal bandwidth usage. But what about lsyncd (Live Syncing Daemon), often just referred to as lsync? Let’s break down the real-world differences and use cases between rsync and lsync with examples to make things crystal clear.

rsync: Manual or Scripted Sync

rsync works by comparing the source and destination, then transferring only the differences. It can be used for local or remote sync, and it’s extremely efficient for backups or one-time file transfers.

Here’s a basic example of rsync:

rsync -avz /var/www/ [email protected]:/backup/www/

This command:

  • syncs files from /var/www/ to a remote server

  • compresses data during transfer (-z)

  • preserves file permissions and timestamps (-a)

  • shows verbose output (-v)

But there’s a catch: rsync doesn’t watch for real-time file changes. If a file is added or modified, you have to run the command again manually or via a cronjob:

*/5 * * * * rsync -avz /var/www/ [email protected]:/backup/www/

This cronjob runs every 5 minutes — decent, but not “real-time”.

lsyncd: Real-Time Syncing with rsync

lsyncd is not a replacement for rsync. It actually uses rsync under the hood, but adds real-time file change monitoring using inotify (on Linux). When a file changes, it instantly triggers an rsync sync — no need for cronjobs.

Here’s a minimal config example for syncing /var/www to a remote server:

settings {
   logfile    = "/var/log/lsyncd.log",
   statusFile = "/var/log/lsyncd.status",
   statusInterval = 20
}

sync {
   default.rsync,
   source = "/var/www/",
   target = "[email protected]:/backup/www/",
   rsync = {
      archive = true,
      compress = true,
      verbose = true
   }
}

Just save that as /etc/lsyncd/lsyncd.conf.lua and start the lsyncd service:

sudo systemctl start lsyncd
sudo systemctl enable lsyncd

Now your files will sync automatically within seconds of being modified.

Performance and Resource Usage

  • rsync is very light — only runs when you tell it to.

  • lsyncd uses more resources due to constant monitoring, but it’s ideal for real-time environments.

If you’re syncing huge numbers of small files in real-time (e.g., a busy web app with file uploads), lsyncd might occasionally choke or delay under heavy file events. In such cases, tuning your config with batching helps:

delay = 5,  -- delay batching of events by 5 seconds

Remember, both rsync and lsyncd do one-way sync. They push from source to destination. If you need two-way syncing, you’ll need tools like Unison or Syncthing.

Share:

More Posts

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments