可以创建rsync等待文件然后同时复制它

Could rsync wait file created and then copy it in the same time

我想使用 "rsync" 将文件从 A 复制到 B,但是文件现在在 A 中不存在。我 运行 B 上的 "rsync" 命令,我可以吗让"rsync"等到文件在A中创建,同时复制?

假设我们从 hostB 上的命令 运行 开始,例如

hostB$ rsync hostA:remotepath localpath

如果 hostA 有一个正常的 shell,我们可以通过调整它通常在 hostA 上运行的帮助命令来让 rsync 等待直到文件存在。根据环境,类似这样的方法可能有效:

hostB$ rsync --rsync-path='
    while [ ! -f remotefile ]; do sleep 1; done;
    sleep 5;
    rsync' hostA:remotepath localpath
  • while 循环忙于等待 remotefile 可用
  • 然后 sleep 5 等待几秒钟让内容稳定下来
  • rsync是普通的远程命令
    • 必须排在最后
    • 不得以换行符、分号或注释结尾