V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
xinmans
V2EX  ›  问与答

如何只同步 A 目录下新加入的文件到 B 目录下?

  •  
  •   xinmans · 3 天前 · 474 次点击
    目前用 rsync 同步 A 目录到 B 目录,由于 A 目录需要保持全量文件,B 目录只需要定期把新增文件同步过来就行
    rsync 的--remove-source-files 会删除源文件,有没有好的办法只同步新增的文件,被同步过的文件不再同步,两个目录 A 和 B 的文件可以有差异?
    6 条回复    2025-02-05 16:39:09 +08:00
    esee
        1
    esee  
       3 天前
    不太理解你的需求,你的意思是 A 中 a 文件先同步到 B 的 a ,如果后面 A 中 a 修改了,也不必同步 到 B 的 a 中,这时候两边的 a 就不同了,是这样吗?
    noqwerty
        2
    noqwerty  
       3 天前 via iPhone
    可以看看 rclone ,印象里有不同的增量同步比较方式
    ntedshen
        3
    ntedshen  
       3 天前
    你是否在找
    --ignore-existing
    xinmans
        4
    xinmans  
    OP
       3 天前
    @ntedshen
    --ignore-existing:要求只更新目标端不存在的文件。和"--existing"结合使用有特殊功能,见下文示例。

    主要是我的目录 B 需要定期删除已经同步的文件,但是 A 目录要保持全量。这个满足不了我的需求。
    xinmans
        5
    xinmans  
    OP
       3 天前
    A 中的文件会不断新增新文件,我只需要把新增的新文件同步到 B 目录,已经同步过的不要同步到 B 目录,我会有一个程序处理 B 目录,会把处理过的文件删除掉。我希望有一个只同步新增文件的过程,且 B 目录的老文件会定期清理掉(因为空间不够)
    xinmans
        6
    xinmans  
    OP
       3 天前
    @noqwerty ,谢谢,好像是可以满足我的需求,i will try
    For example, if you have many files in /path/to/src but only a few of them change every day, you can copy all the files which have changed recently very efficiently like this:

    rclone copy --max-age 24h --no-traverse /path/to/src remote:
    Rclone will sync the modification times of files and directories if the backend supports it. If metadata syncing is required then use the --metadata flag.

    Note that the modification time and metadata for the root directory will not be synced. See https://github.com/rclone/rclone/issues/7652 for more info.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2818 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 18ms · UTC 13:38 · PVG 21:38 · LAX 05:38 · JFK 08:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.