简体   繁体   中英

Preserving ownership of file with Lsyncd

I have two servers: source-server and target-server. I want use lsyncd to sync files in a directory on source-server to another directory on target-server.

In my ssh daemon, on both servers, I have root logins disabled ( PermitRootLogin no ) so I can't use the root user to run lsyncd over ssh.

I created a user 'syncer' on both servers that has a key-pair allowing password-less ssh logins from source-server to target-server. So this works:

[syncer@source-server]$ ssh syncer@target-server

My lsyncd.conf looks like this:

settings = {
    logfile = "/var/log/lsyncd.log",
    statusFile = "/var/log/lsyncd.stat",
    statusInterval = 2
}


sync {
    default.rsync,
    source="/var/www/html/",
    target="target.server.ip:/backup/",
    rsync = {
        rsh ="/usr/bin/ssh -l syncer -i /home/syncer/.ssh/id_rsa",
        compress = true,
        acls = true,
        xattrs = true,
        archive = true
    }
}

And it works except the owner of replicated files on the target server is always 'syncer'. The permissions of the source are respected and replicated correctly on the target. I just can't figure out a way to preserve the owner (and group) of the replicated files. (ie, if the file on source is owned by 'deknuth', I would like the synced file on target to also be owned by 'deknuth' not 'syncer').

TIA

To close this out, using the non-root user will always move a file with that non-root user being the owner on the destination -- regardless of who owned it on the source. This may be acceptable. If not, run lsyncd as root and allow root logins with a key pair.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM