View all posts

How to install lsyncd

What is lsyncd?

The lsyncd tool monitors specified directories (including subdirectories) for updates and modifications and then syncs those changes to a specified destination. Using the Lua programming language, it is an easy-to-install and easy-to-configure lightweight command application.

Install lsyncd

As a first step, we will ensure that the list of available packages on the server is up to date before installing anything new.

Ubuntu

apt-get -y update && apt-get upgrade -y

CentOS

yum update -y

Our next step will be to install lsyncd and any required packages.

Ubuntu

apt-get -y install lsyncd

CentOS

yum install lsyncd -y

This is how you can restart & enable lsyncd.

systemctl start lsyncd
systemctl enable lsyncd

You can now verify your installation.

lsyncd --version

Configuration

Now we will create a new lsyncd config file with our information stored in it. We will use this file to define the sources and destinations of the sync.

vim /etc/lsyncd/lsyncd.conf.lua

An example configuration to sync 2 local folders would look like this.

settings {
         logfile = "/var/log/lsyncd/lsyncd.log",
         statusFile = "/var/log/lsyncd/lsyncd.status",
    statusInterval = 30,
    nodaemon   = false
 }
 sync {
         default.rsync,
         source = "/home/quickhostuk/public_html",
         target = "/backup/quickhostuk/public_html"
 }

An example configuration to sync local to remote folders would look like this.

settings {
         logfile = "/var/log/lsyncd/lsyncd.log",
         statusFile = "/var/log/lsyncd/lsyncd.status",
    statusInterval = 30,
    nodaemon   = false
 }
 sync {
        default.rsyncssh,
        source = "/home/quickhostuk/public_html",   
        targetdir = "/backup/quickhostuk/public_html",
        host = "192.168.1.2",
        delay           = 5,
        rsync = { rsh="/usr/bin/ssh -l sshuser -i /home/sshuser/.ssh/id_rsa -o StrictHostKeyChecking=no"}
}

Once this is complete, you are finished with the setup process and can now begin synchronizing your files from your source directory to your target directory.

Related Articles...

Install LAMP

How to install LAMP Stack on Ubuntu 20.04

What is LAMP? The LAMP acronym stands for Linux, Apache, MariaDB/MySQL, and PHP, all of which are free and open source. It is the most commonly used software stack for dynamic websites and web applications. The operating system is Linux, the... Read more

This website uses cookies

We use cookies for the analysis of our visitor data, to improve our website, and to give you a great website experience. For more information about the cookies we use, please see our cookie policy.