如何使用rsync来备份最近一段时间内更改过的文件?
是否可以指定一个时间范围,以便 rsync 仅对最近更改的文件进行操作。
我正在编写一个脚本来通过 SSH 备份最近添加的文件,rsync 似乎是一个有效的解决方案。 我的问题是我的源目录包含大量积压的旧文件,我没有兴趣备份这些文件。
到目前为止,我遇到的唯一解决方案是使用 ctime 进行查找以生成 --files-from 文件。 这可行,但我必须处理一些旧安装,其 rsync 版本不支持 --files-from。 我正在考虑以相同的方式生成 --include-from 模式,但希望找到更优雅的东西。
Is it possible to specify a time range so that rsync only operates on recently changed files.
I'm writing a script to backup recently added files over SSH and rsync seems like an efficient solution. My problem is that my source directories contain a huge backlog of older files which I have no interest in backing up.
The only solution I've come across so far is doing a find with ctime to generate a --files-from file.
This works, but I have to deal with some old installations with versions of rsync that don't support --files-from.
I'm considering generating --include-from patterns in the same way but would love to find something more elegant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来您可以在 rsync 的参数中指定 shell 命令(请参阅远程 rsync 执行任意 shell 命令
)我已经能够通过使用以下方法成功限制 rsync 查看的文件:
这会查找最后一天 (-ctime -1) 中更改的任何文件,然后将这些文件 rsync 到 local_dir 中。
我不确定此功能是否是设计使然,但我仍在深入研究文档。
It looks like you can specify shell commands in the arguments to rsync (see Remote rsync executes arbitrary shell commands)
so I have been able to successfully limit the files that rsync looks at by using:
This looks for any files changed in the last day (-ctime -1) and then rsyncs those into local_dir.
I'm not sure if this feature is by design but I'm still digging into the documentation.
为什么不热衷于备份整个目录一次并利用 rsync 和 rdiff 及其同类提供的增量备份,您不会浪费它们备份的磁盘空间,因为它们将永远不变。
备份整个数据变得更加简单,并且出错的风险大大降低。 尝试有选择地备份某些文件而不备份其他文件,会导致您在没有意识到的情况下不备份您需要的文件,然后在无法恢复关键文件时被烧毁。
否则,您应该重新组织源目录,以便备份脚本中减少“决策”。
Why not just take the heat on backing up the whole directory once and take advantage of the incremental backing up provided by rsync and rdiff and its cousins, you won't waste diskspace where they are backed up to because they'll be perpetually unchanged.
Backing up the whole thing is simpler, and has substantially less risk for errors. Trying to selectively backup some files and not others is a recipe for not backing up what you need without realizing it, then getting burned when you can't restore a critical file.
Otherwise you should reorganize your source directory so there is less 'decision making' in your backup script.
创建一个临时目录,对其中的文件进行符号链接或硬链接,然后进行 rsync 怎么样?
How about creating a temporary directory, symlinking or hardlinking the files in, then rsyncing that?
我可以建议你放弃 rsync 并查看 rdiff-backup 吗?
May I suggest you drop rsync and look at rdiff-backup?