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

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

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

答案1

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

--info=FLAGS            fine-grained informational verbosity

有关如何使用它的解释位于-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.)

因此如下:

rsync -r --info=progress2 --info=name0 "$src" "$dst"

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

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

请注意,当传输开始时,使用递归选项时,随着发现更多文件进行同步,总块数(因此当前进度)可能会发生变化

答案2

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

手册页/explainshell

-a, --archive
-v, --verbose
-z, --compress
-h, --human-readable

--progress  This  option  tells  rsync to print information showing
 the progress of the transfer. This gives a bored user something to
 watch.  Implies --verbose if it wasn’t already specified.

--stats  This  tells  rsync to print a verbose set of statistics on
 the file transfer, allowing you to tell how effective rsync’s
 delta-transfer algorithm is for your data.

答案3

这个怎么样?

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

    避免重复输入参数

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

    确定要完成的步骤数。

  • a/ b

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

答案4

这最终奏效了:

rsync "$rsync_param" -a --prune-empty-dirs --exclude "*.iso" rsync://archive.ubuntu.com/ubuntu/indices/ /repo/ubuntu/indices | pv -lep -s $(rsync "$rsync_param"n rsync://archive.ubuntu.com/indices/ /repo/ubuntu/indices | awk 'NF' | wc -l)

相关内容