Lsyncd: An Easy Way For Live Synchronization Of Directories On Linux

Lsyncd (Live Syncing Daemon) is a light-weight live mirror solution between two directories. It uses rsync and ssh. Custom configuration profiles can be written in the Lua language (see example below).

Lsyncd home page is available here. It is also available from a GitHub repository.

Setup

Setup on Debian/Ubuntu

sudo apt-get install lsyncd

Setup on Centos/RHEL

See here and here.

Setup on Archlinux

Available from the AUR repository. See here.

Example configuration

The following example describes a live syncing of the project “/data/projects/myproject” (source) to “/store/backup/myproject” (target) in a Debian/Ubuntu system. Some files are excluded (.git, vendor, etc).

As root

systemctl stop lsyncd.service

Create the following:

mkdir /etc/lsyncd
mkdir /var/log/lsyncd
touch /var/log/lsyncd/lsyncd.log
touch /var/log/lsyncd/lsyncd.status

Create the config file

nano /etc/lsyncd/lsyncd.conf.lua

Add the following:

settings {
	logfile = "/var/log/lsyncd/lsyncd.log",
	statusFile = "/var/log/lsyncd/lsyncd.status"
}
 
sync {
	default.rsync,
	source = "/data/projects/myproject",
	target = "/store/backup/myproject",
 	exclude = {'.git/' , 'vendor/', 'web/node_modules', 'bundled/'},
        rsync     = {
            archive  = true,
            compress = true
        }	
}

If you want to sync more than one directories, add more “sync” blocks.

Finally

systemctl start lsyncd.service

Combine with Dropbox

If the target directory is inside your Dropbox, you will have both a local and a cloud clone of the source directory.

Lsyncd alternatives

Your comments are welcome!


Never Miss A Post!

Subscribe to our free NewsLetter