镜像文件通过rsync移动
我们用于备份的专有软件 (sadface) 生成一系列图像,我们使用 rsync 将其同步到异地位置。 生成的文件看起来像这样:
a.bak
b.bak
c.bak
因此我们同步这些文件并在场外计算机上获得完全相同的结构。 然后备份程序再次运行,我们得到如下结果:
archive/a.bak
archive/b.bak
c.bak
d.bak
e.bak
因此 rsync 作业运行,我们最终得到如下结果:
archive/a.bak
archive/b.bak
a.bak
b.bak
c.bak
d.bak
e.bak
显然,我们希望场外计算机看起来像现场计算机这样做,以避免混乱并节省存储空间。 有没有办法让 rsync 反映现场发生的动作,或者我们是否必须在 rsync 之外解决一些问题?
The proprietary software that we're using for backups (sadface) generates a series of images that we use rsync
to sync over to an off-site location. The files generated look something like:
a.bak
b.bak
c.bak
So we sync those across and get exactly the same structure on the off-site machine. Then the backup program runs again and we get something like:
archive/a.bak
archive/b.bak
c.bak
d.bak
e.bak
So the rsync
job runs and we end up with something like:
archive/a.bak
archive/b.bak
a.bak
b.bak
c.bak
d.bak
e.bak
Obviously, we would prefer the off-site machine to look like the on-site machine does, to avoid clutter and save on storage space. Is there any way to get rsync
to mirror the moves that have happened on-site, or are we going to have to work out something outside of rsync
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道有什么方法可以让它智能地检测到文件只是“移动”了。 但是,您可以使用
--delete
标志,以便从目标中删除源中不再存在的文件。 缺点是,每当文件移动时,您都会重新复制该文件,但至少您不会再为目标上的旧位置浪费空间。I don't know of any way to have it intelligently detect that the file has simply "moved". You can, however, use the
--delete
flag, so that it'll delete files from the destination that no longer exist on the source. The downside is that you'll re-copy the file whenever it moves, but at least you won't be wasting space for the old location on the destination anymore.对于这个问题有一个非常巧妙的解决方案。 它需要额外的空间,但可以避免大量的流量浪费。 我在 https://lincolnloop.com/blog/detecting- 中找到了它file-moves-renames-rsync/
查看那里的详细信息,但基本上,您在两侧进行任何更改之前都会创建一个硬链接备份树,然后修改原始树。 当 rsync 时,您使用一个额外的选项来保留硬链接,这足以让 rsync 检测重复文件并避免再次复制它们。
There is a very clever solution to this problem. It takes an extra bit of space, but it saves you from so much wasted traffic. I've found it in https://lincolnloop.com/blog/detecting-file-moves-renames-rsync/
See the details there, but basically, you make a hard-link backup tree before making any changes, on both sides, and then modify the original tree. When rsync'ing, you use an extra option to keep hard-links, and that's enough for rsync to detect the duplicate files and avoid copying them again.
如果您使用 --times 开关并确保两端都有时钟同步,那么您可以使用 --update 和 --delete 选项仅传输较新的文件并删除不应该存在的文件。
有关完整选项,请参阅 rsync 手册页。
If you use the --times switch and make sure both ends have clock syncing and then you can use --update and --delete options to only transfer newer files and prune away files that shouldn't be there.
See the rsync man page for full options.