运行 rsync 时如何查看进度条?

Jos*_*ith 52 rsync

我使用 Ubuntu 12.04 作为存储库,并希望rsync在从命令行使用时查看进度条。我尝试了本文( -P) 中建议的选项,但我更喜欢查看进度条而不是使用 Grsync。我rsync -P source dest目前正在使用。

Jon*_*Jon 71

rsync 有一个--info选项,不仅可以用来输出当前的进度,还可以输出传输速率和经过的时间:

--info=FLAGS            fine-grained informational verbosity
Run Code Online (Sandbox Code Playgroud)

如何使用它的解释来自-P手册页中的选项:

-P     The -P option is equivalent to --partial --progress.  Its purpose is to
       make it much easier to specify these two options for a long transfer that
       may be interrupted.

       There is also a --info=progress2 option that outputs statistics based on
       the whole transfer, rather than individual files.  Use this flag
       without  out?putting  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.)
Run Code Online (Sandbox Code Playgroud)

所以如下:

rsync -r --info=progress2 --info=name0 "$src" "$dst"
Run Code Online (Sandbox Code Playgroud)

结果输出如下并不断更新:

18,757,542,664 100%   65.70MB/s    0:04:32 (xfr#1389, to-chk=0/1510)
Run Code Online (Sandbox Code Playgroud)

请注意,当传输开始时,块的总数以及当前的进度会在使用递归选项时更改,因为发现更多文件进行同步

  • 快速说明:“--no-ir”选项禁用增量递归,这意味着 rsync 将在开始传输之前找到所有文件。这使得百分比更加准确,但我建议仅将其用于本地转账。请参阅 https://serverfault.com/questions/219013/showing-total-progress-in-rsync-is-it-possible (5认同)
  • 嗯,我的 `--info=progress2` 进度条显示过去 20 小时还剩 8 分钟,并从 99% 上下跳到 97%、98%、96%?这样做的目的是什么?:D (2认同)

fug*_*ive 26

您可以使用--progress--stats参数。

rsync -avzh --progress --stats root@server:/path/to/file output_name

root@server's password: 
receiving incremental file list
file
         98.19M  54%    8.99MB/s    0:00:08
Run Code Online (Sandbox Code Playgroud)

  • 这在 macOS 上对我有用。 (5认同)
  • `--stats` 具体有什么作用?仅使用“--progress”即可获得“98.19M 54% 8.99MB/s 0:00:08”部分。 (3认同)
  • @JoshuaPinter我相信你最后得到的统计数据,即文件数、传输的文件数、总字节数等由 --stats 提供 (3认同)

A.B*_*.B. 13

这个怎么样?

rsync_param="-av"
rsync "$rsync_param" a/ b |\
     pv -lep -s $(rsync "$rsync_param"n a/ b | awk 'NF' | wc -l)
Run Code Online (Sandbox Code Playgroud)
  • $rsync_param

    避免参数的双重输入

  • $(rsync "$rsync_param"n a/ b | awk 'NF' | wc -l)

    确定要完成的步骤数。

  • a/ b

    1. a/ 是来源
    2. b 是目标

  • `"$rsync_param"n` 很奇怪;引号意味着它只能对没有空格的选项起作用,并且将 `n` 附加到末尾意味着它只能对短选项起作用。更清晰、更简单的是`$rsync_param -n`,它指定dry-run而不依赖于`rsync_param`的格式,并且通过不引用它,也可以包含长选项 (2认同)