# Setup and Configure Lsyncd

> Lsyncd watches a local directory trees event monitor interface (inotify or fsevents)

- Canonical URL: <https://carlossura.com/blog/setup-and-configure-lsyncd/>
- Author: Carlos Sura
- Published: 2024-12-24
- Tags: lsyncd, ubuntu, linux

I was looking for my options to sync files from **Server A** to **Server B** so I found **Lsyncd**

For the installation

```
sudo apt update
sudo apt install lsyncd
```

We need to create the configuration

```
sudo mkdir /etc/lsyncd /var/log/lsyncd
```

Now, create the following file

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

And add the following configuration

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

sync {
    default.rsyncssh,
    source = "/home/folder/tosync",
    host = "ubuntu@127.0.0.1",
    targetdir = "/home/folder/destination",
}
```

If you want to add a custom SSH port and prevent deletion you can do the following:

```
sync {
    default.rsyncssh,
    source = "/home/folder/tosync",
    host = "ubuntu@127.0.0.1",
    targetdir = "/home/folder/destination",
    rsync = {
        rsh = "ssh -p 99999",  -- Specify the custom SSH port
    },
    delete = "false"  -- Explicitly disable delete behavior
}
```
