Lsyncd – How to sync files and folders preserving user and group

Lsyncd – How to sync files and folders preserving user and group

Lsyncd - How to sync files and folders preserving user and group

As we have configured lsyncd daemon to keep files between two computers in perfect live sync. When we setup lsyncd with root user by default it will synced files will be owned by root user & group.

In newer version of lsync 2.1 and above, we can configure lsyncd to perserve same user and group of files and folders. We can configure the same in lsyncd.lua or lsyncd.conf. We need to update rsync block to include such setting:

perms = true;
owner = true;
group = true;

after changing the lsynd.conf restart its lsyncd service. After restart you can find the lsyncd will preserve same user and group permission that is present on master server. However, we same user and group should be avaialble on slave server too.

Restart lsyncd daemon on RHEL 7

$ systemctl restart lsyncd

Restart lsyncd daemon on Debian / Ubuntu

$ sudo systemctl restart lsyncd

$ sudo /etc/init.d/lsyncd restart

Sample configuration file:

Sample configuration file in text format:

$ vi /etc/lsyncd.conf

 

— User configuration file for lsyncd.

— Simple example for default rsync, but executing moves through on the target.

settings {
logfile = “/var/log/lsyncd/lsyncd.log”,
statusFile = “/var/log/lsyncd/lsyncd-status.log”,
statusInterval = 60
}
sync {
default.rsyncssh,
source = “/storage”,
exclude = {“/web/dir/logs”,”/web/dir/tmp”},
host = “192.168.1.1”,
targetdir = “/storage”,

rsync = {
compress = true,
verbose = true,
update = true,
perms = true,
owner = true,
group = true,
rsh = “/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no -eg”
}
}

Leave a Reply

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