Wie kann ich beim Ausführen von rsync einen Fortschrittsbalken anzeigen?

Wie kann ich beim Ausführen von rsync einen Fortschrittsbalken anzeigen?

Ich verwende Ubuntu 12.04 als Repo und möchte bei der Verwendung rsyncüber die Befehlszeile einen Fortschrittsbalken anzeigen. Ich habe die Optionin diesem Artikel vorgeschlagen( -P), aber ich möchte lieber einen Fortschrittsbalken sehen und nicht Grsync verwenden. Ich verwende rsync -P source destderzeit.

Antwort1

rsync verfügt über eine --infoOption, mit der sich neben dem aktuellen Fortschritt auch die Übertragungsrate und die verstrichene Zeit ausgeben lassen:

--info=FLAGS            fine-grained informational verbosity

Die Erklärung zur Verwendung finden Sie unter der -POption auf der Manpage:

-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.)

Also folgendes:

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

Das Ergebnis ist, dass Folgendes ausgegeben und kontinuierlich aktualisiert wird:

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

Beachten Sie, dass sich beim Start der Übertragung die Gesamtzahl der Blöcke und damit der aktuelle Fortschritt ändern kann, wenn die rekursive Option verwendet wird, da mehr Dateien zum Synchronisieren gefunden werden

Antwort2

Sie können --progressund --statsParameter verwenden.

$ 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

Ausmanpage/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.

Antwort3

Wie wäre es damit?

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

    Vermeidet die doppelte Eingabe von Parametern

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

    Bestimmt die Anzahl der abzuschließenden Schritte.

  • a/ b

    1. a/ist die Quelle
    2. bist das Ziel

Antwort4

Das hat endlich geklappt:

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)

verwandte Informationen