简体   繁体   English

使用lsyncd使用远程源更新本地文件夹吗?

[英]Use lsyncd to update a local folder with a remote source?

I've used lsyncd to sync a local folder to a server I own using rsyncssh with a config file like this: 我已经使用lsyncd将本地文件夹同步到我自己的服务器,该服务器使用rsyncssh和如下配置文件:

settings = {
        logfile = "/var/log/lsyncd/lsyncd.log",
        statusFile = "/var/log/lsyncd/lsyncd.status"
}
sync {
        default.rsyncssh,
        source = "/Users/user/source",
        host = "root@xxx.xxx.xxx.xxx",
        targetdir = "/tmp/data",
        rsync = { binary = "/usr/local/bin/rsync" }
} 

Now, I want to perform a "pull" to sync a local directory on another machine (different network) with that remote server. 现在,我想执行“拉”操作以将另一台计算机(不同网络)上的本地目录与该远程服务器同步。

I'm using this config file: 我正在使用此配置文件:

settings = {...}
sync {
        default.rsync,
        source = "root@xxx.xxx.xxx.xxx:/tmp/data",
        target = "/home/user/dest",
        rsync = { binary = "/usr/local/bin/rsync", _extra = { "-P", "-e", "ssh" } }
}

but I got this error: 但是我得到了这个错误:

Error: failure getting absolute path of [root@xxx.xxx.xxx.xxx:/tmp/data]
Error: Cannot access source directory: root@xxx.xxx.xxx.xxx:/tmp/data

Of course /tmp/data exists, any hint what I'm doing wrong? 当然/ tmp / data存在,是否暗示我在做什么错?

Do you know if it is possible to use lsyncd with rsync the way I'm using it to keep a local folder "up-to-date" with a remote source? 您是否知道是否可以将lsyncd与rsync一起使用,以使其与远程源保持本地文件夹“最新”的方式? Or can I use rsyncssh with a remote source? 还是可以将rsyncssh与远程源一起使用?

Thanks! 谢谢!

lsyncd cannot do this because it's not designed this way. lsyncd无法做到这一点,因为它不是以这种方式设计的。 It's intended to use inotify events to monitor a directory and then launch rsync to do the heavy lifting. 它旨在使用inotify事件来监视目录,然后启动rsync进行繁重的工作。 inotify is inherently a local concept, and lsync doesn't actually do any network communications itself. inotify本质上是一个本地概念,lsync实际上并不进行任何网络通信。

What you need to do is run an lsyncd service on the server that will launch an rsync configured to connect to your client machine. 您需要做的是在服务器上运行lsyncd服务,该服务将启动配置为连接到客户端计算机的rsync。

That means you'll need to set up an ssh server on your local machine. 这意味着您需要在本地计算机上设置ssh服务器。 If your machine doesn't have a suitable domain name/IP address, or is behind a NAT or firewall, then you'll need to set up an ssh -R reverse tunnel and route your server-to-client rsync through that. 如果您的计算机没有合适的域名/ IP地址,或者位于NAT或防火墙之后,则需要设置ssh -R反向隧道并通过该路径路由服务器到客户端的rsync。

Once it's set up it'll work, but honestly, you might find it's easier to use SyncThing. 设置完成后就可以使用,但是说实话,您可能会发现使用SyncThing会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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