监控 Rsync 进度

发布于 2024-11-30 22:51:06 字数 417 浏览 1 评论 0原文

我正在尝试编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

女皇必胜 2024-12-07 22:51:06

当前版本的 rsync(编辑 3.1.2 时)有一个选项 --info=progress2 ,它将显示整个传输的进度而不是单个文件。

来自手册页

还有一个 --info=progress2 选项,可以根据整个传输而不是单个文件输出统计信息。使用此标志而不输出文件名(例如,如果您想在不滚动屏幕并显示大量名称的情况下查看传输情况,请避免 -v 或指定 --info=name0。(您不需要指定 --进度选项以便使用 --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:

There is also a --info=progress2 option that outputs statistics based on the whole transfer, rather than individual files. Use this flag without outputting a filename (e.g. avoid -v or specify --info=name0 if you want to see how the transfer is doing without scrolling the screen with a lot of names. (You don't need to specify the --progress option in order to use --info=progress2.)

So, if possible on your system you could upgrade rsync to a current version which contains that option.

半枫 2024-12-07 22:51:06

您可以使用参数 --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.

过气美图社 2024-12-07 22:51:06

请注意这里的警告,即使 --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.

毁我热情 2024-12-07 22:51:06

为了完全控制传输,您应该使用更底层的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文