监控 Rsync 进度
我正在尝试编写一个 Python 脚本来监视 rsync 传输,并提供进度百分比的(粗略)估计。在我的第一次尝试中,我查看了 rsync --progress 命令,发现它打印的消息如下:
1614 100% 1.54MB/s 0:00:00 (xfer#5, to-check=4/10)
我为此类消息编写了一个解析器,并使用 to-check 部分来生成进度百分比,在这里,这将完成 60%。
然而,这样做有两个缺陷:
- 在大额传输中,待检查分数的“分子”似乎不是单调递减的,因此百分比完整性可能会向后跳跃。
- 并非所有文件都会打印这样的消息,这意味着进度可以向前跳跃。
我已经查看了其他可使用的消息替代方案,但没有找到任何东西。有人有什么想法吗?
提前致谢!
I'm trying to write a Python script which will monitor an rsync transfer, and provide a (rough) estimate of percentage progress. For my first attempt, I looked at an rsync --progress
command and saw that it prints messages such as:
1614 100% 1.54MB/s 0:00:00 (xfer#5, to-check=4/10)
I wrote a parser for such messages, and used the to-check part to produce a percentage progress, here, this would be 60% complete.
However, there are two flaws in this:
- In large transfers, the "numerator" of the to-check fraction doesn't seem to monotonically decrease, so the percentage completeness can jump backwards.
- Such a message is not printed for all files, meaning that the progress can jump forwards.
I've had a look at other alternatives of messages to use, but haven't managed to find anything. Does anyone have any ideas?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当前版本的 rsync(编辑 3.1.2 时)有一个选项
--info=progress2
,它将显示整个传输的进度而不是单个文件。来自手册页:
因此,如果您的系统上可能的话,您可以将 rsync 升级到包含该选项的当前版本。
The current version of rsync (at the time of editing 3.1.2) has an option
--info=progress2
which will show you progress of the entire transfer instead of individual files.From the man page:
So, if possible on your system you could upgrade rsync to a current version which contains that option.
您可以使用参数
--no-inc-recursive
禁用增量递归。 rsync 将对整个目录结构进行预扫描,因此它知道必须检查的文件总数。这实际上是递归的老方法。添加当前默认的增量递归是为了提高速度。
You can disable the incremental recursion with the argument
--no-inc-recursive
. rsync will do a pre-scan of the entire directory structure, so it knows the total number of files it has to check.This is actually the old way it recursed. Incremental recursion, the current default, was added for speed.
请注意这里的警告,即使
--info=progress2
也不完全可靠,因为这是基于 rsync 知道的文件数量的百分比显示进度的时间。这不一定是需要同步的文件总数(例如,如果它在深层嵌套目录中发现大量大文件)。确保
--info=progress2
不会在进度指示中跳回的一种方法是强制 rsync 在开始同步之前递归扫描所有目录(而不是进行增量递归扫描的默认行为),还提供--no-inc-recursive
选项。但请注意,此选项也会增加 rsync 内存使用量和运行时间。Note the caveat here that even
--info=progress2
is not entirely reliable since this is percentage based on the number of files rsync knows about at the time when the progress is being displayed. This is not necessarily the total number of files that needed to be sync'd (for instance, if it discovers a large number of large files in a deeply nested directory).One way to ensure that
--info=progress2
doesn't jump back in the progress indication would be to force rsync to scan all the directories recursively before starting the sync (instead of its default behavior of doing an incrementally recursive scan), by also providing the--no-inc-recursive
option. Note however that this option will also increase rsync memory usage and run-time.为了完全控制传输,您应该使用更底层的 diff 工具并自己管理目录列表和数据传输。
基于 librsync,有命令行 rdiff 或 python 模块 pysync
For full control over the transfer you should use a more low-level diff tool and manage directory listing and data transfer yourself.
Based on librsync there is either the command line rdiff or the python module pysync