How to sync files with lsyncd

lsyncd

Introduction

We’ve already talked about using tools like rsync for managing backup of your systems, but there’s another “problem” which has to be solved if you have multiple remote computers: synchronization.
In this article, we’ll talk about lsyncd, a daemon that enables you to mirror your directories to any other directory on your network, or even locally. For performance purposes, it only mirror changes to your directory.

Install

If you use Ubuntu, you’ll find it already in the repositories:

# apt install lsyncd

If you’re a RHEL/CentOS/Fedora user, then you have to enable EPEL first. Then:

# yum install lsyncd

After installation, you’ll find sample configurations in /usr/share/doc/lsyncd/examples/ or in /usr/share/doc/lsyncd-VERSION/examples/, depending on whether you are using Ubuntu or RedHat-based distros.

Configuring a local syncing

So, for testing, let’s try a local syncing with lsyncd.
First, let’s create a “source folder”, containing the files we want to sync.

$ mkdir -p $HOME/unixmen/sync_source

Then, we’ll make a backup folder:

$ mkdir $HOME/sync_backup

Just for test, populate the source directory with zero-lenght files, using touch command:

touch $HOME/unixmen/sync_source/unixmentest{1..10}0

Now, make log and status files:

# mkdir /var/log/lsyncd
# touch /var/log/lsyncd.{log,status}

Configuration file goes on /etc/lsyncd:

# mkdir /etc/lsyncd

In there, we’ll create a new config file:

# nano /etc/lsyncd/lsyncd.conf.lua

Where we’ll put the following code:

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

sync {
default.rsync,
source = "$HOME/unixmen/sync_source/",
target = "$HOME/sync_backup",
}

Right now, if you look in the backup directory, you’ll find it empty, because the service is not running.
But, to solve this, simply restart lsyncd with the following:

# systemctl restart lsyncd

It will start (and keep) syncing, even if you add more files on sync_source. It works completely in automated mode.

Conclusion

In a similar way, you can sync remote files, with just the difference that you’ll use SSH, and varying just a little bit in the conf file.
There are a lot of examples that you can look for in /usr/share/doc/lsyncd/examples/, or just lsyncd documentation. Happy syncing!

  • I have made $104,000 previous year by doing an online job from my house and I did it by w­o­r­k­i­n­g part time f­­o­­r several hours on daily basis. I used an earning model I stumbled upon online and I am so thrilled that i made so much money. It’s so user friendly a­­n­­d I’m so blessed that I found out about this. Check out what I did… STATICTAB.COM/x4biwaa

  • I was paid $104000 in 2016 by doing an online job a­n­d I did it by w­o­r­k­i­n­g part-time f­­o­­r few h each day. I followed work model I was introduced by this web-site i found online and I am amazed that i was able to make so much money. It’s very beginner-friendly a­­n­­d I’m so blessed that i discovered this. Here’s what I did… STATICTAB.COM/x4biwaa

  • I was paid 104 thousand bucks in last twelve months by doing an online job at my house and I did it by w­orking part time f­­o­­r 3+ hrs /day. I’m using work model I found online and I am so amazed that I was able to earn so much money on the side. It’s so user friendly a­­n­­d I am just so blessed that i learned about it. Here is what i do… STATICTAB.COM/gpfvgtj

  • I was paid 104000 bucks in last twelve months by doing an on-line job and I was able to do it by w­orking part-time f­o­r few h a day. I used work opportunity I found on-line and I am so amazed that i was able to make so much money on the side. It’s so beginner-friendly a­­n­­d I am just so grateful that i found this. Here’s what I do… STATICTAB.COM/r2tyhgi

  • I got paid 104000 dollars in 2016 by doing an online job from my house a­n­d I did it by w­orking in my own time for 3+ hours /day. I’m using a business opportunity I found online and I am so amazed that I was able to earn so much money. It’s very user friendly a­­n­­d I’m just so thankful that i learned about it. Check out what I did… STATICTAB.COM/astkxim

  • I was paid 104 thousand bucks in 2016 by doing an on-line job from my house a­n­d I did it by work­ing part time for few hours every day. I used an earning model I stumbled upon online and I am so thrilled that i made so much extra income. It’s very beginner-friendly and I’m so thankful that I found out about this. Check out what I do… STATICTAB.COM/astkxim

  • I’ve earned 104 thousand dollars in last 12 months by working on-line from home and I did that by working in my own time f­­o­­r several h /day. I was following a business opportunity I was introduced by this company i found online and I am so excited that I was able to earn so much money on the side. It’s very newbie friendly a­­n­­d I’m so happy that i discovered it. Here is what i did… please visit my account for webpage

  • I got paid $104k in 2016 by freelancing from home a­n­d I did it by wor­king part time f­o­r 3+ hrs daily. I was following a money making model I stumbled upon from this website i found online and I am so happy that I was able to earn so much extra income. It’s so user friendly a­­n­­d I am just so happy that i discovered it. This is what i did…TWITTER.COM/StinnettMargar1/status/835739136078163968