1. Home
  2. Linux
  3. Sync file lsyncd on linux

How to sync your files using lsyncd on Linux

Lsync is a lightweight syncing alternative to Rsync. It works roughly in the same way in that it scans a set directory for changes and syncs it to any place that the user wants. The application works as a background service and is readily available for installation on many mainstream Linux distributions. To get Lsyncd on Linux, open up a terminal window and follow the instructions that correspond to your operating system.

Note: be sure to install the app on all of the computers you wish to sync to.

Ubuntu

sudo apt install lsyncd

Debian

sudo apt-get install lsyncd

Arch Linux

Lsyncd is available for Arch Linux, though it’s not in the primary software sources, so installing it with the Pacman package management tool isn’t possible. Instead, those looking to use the Live Sync Daemon on Arch must download, build and set it up from the AUR.

To get the application working on Arch Linux, launch a terminal and follow the instructions below.

Step 1: Using Pacman, install both Base-devel and Git. These packages are essential, and you will not be able to interact with the Lsyncd AUR package without them.

sudo pacman -S git base-devel

Step 2: Clone the latest Lysncd AUR snapshot from the official Arch Linux User Repository website.

git clone https://aur.archlinux.org/lsyncd.git

Step 3: Change the terminal’s starting directory from the home folder to the newly cloned “lsyncd” directory using the CD command.

cd lsycnd

Step 4: Compile and generate an installable package for your Arch Linux PC by executing the makepkg command. Please note that when you’re using makepkg, the package may fail to build. If this happens, refer to the Lsyncd AUR page and read the user comments for guidance.

makepkg -sri

Fedora

sudo pacman -S lsyncd

OpenSUSE

sudo zypper install lsyncd

Generic Linux

Can’t find Lsycnd for your Linux operating system? If so, you may need to download the program and build it from source. Open up a terminal and follow the step-by-step instructions to learn how to get Lsycnd built and running.

Step 1: The app has a lot of dependencies that must be installed. Check the list below and grab each of these packages.

  • Cmake
  • Lua (5.2 or later)
  • Liblua (5.2 or later)
  •  GCC compiler
  • Lua compiler
  • Make
  • Binutils
  • Git

More information on needed dependencies can be found on GitHub.

Step 2: Use Git and clone the source code to your Linux PC.

git clone https://github.com/axkibe/lsyncd.git

Step 3:Move into the Lsyncd code folder with the CD command.

cd lsyncd

Step 4: Make a new build directory in the code folder.

mkdir build

Step 5: Move the terminal session into the new build directory.

cd build

Step 6: Run cmake to start the code compilation process.

cmake ..

Step 7: Finish up the compilation process with the make command.

make

Step 8: Install the app to your Linux computer with make install.

sudo make install

Configure Lsyncd

The Lsyncd service runs in the background. Unfortunately, the service doesn’t start up and enable itself manually. As a result, before we can interact with Lsyc, we must start the background service using the systemctl command.

sudo service lsyncd start

With the service started, we can make a new configuration file using the touch command.

sudo touch /etc/lsyncd.conf

Please note that on some operating systems, creating a file at /etc/lsynd.conf may not work. It may be necessary to create a configuration file in /etc/lsyncd/ instead.

sudo mkdir -p /etc/lsyncd/
sudo touch /etc/lsyncd/lsyncd.conf.lua

Open up the configuration file with the Nano text editor.

sudo nano /etc/lsyncd.conf

Or, if you set the configuration in /etc/lsyncd/, do:

sudo nano /etc/lsyncd/lsyncd.conf.lua

Paste the code below into the configuration file:

settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.stat",
statusIntervall = 1,
nodaemon = false
}

After the code is in the Nano text editor, save it by pressing the Ctrl + O keyboard combination. Then, exit it with Ctrl + X.

Set up shared folder

Now that the core of the configuration folder is set up, we need to set up a syncing system. To set up a syncing system, go back to Nano and paste the code in lsyncd.conf, directly below what was added earlier.

Note: be sure to go through the sync code and change it so that it suits your needs.

sync {
default.rsyncssh,
source = "/source/folder/location",
host = "remote-pc-or-server-ip",
targetdir = "/remote/directory"
}

Once again, save the edits to the lsyncd.conf folder in Nano with Ctrl  + O.

Start the sync

Lsync is all set and ready to go. Now it’s time to start the synchronization process. In a terminal, use the service command to restart it.

sudo service restart lsyncd

By rebooting Lsync with the service command, it’ll read the new configuration file and instantly start syncing data.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.