我在腳本(在 OSX 上)中使用 rsync 從 raid 複製到 2 個備份驅動器,這種情況在我運行腳本時發生,一天可能複製 10-20 倍。我正在嘗試找出一種方法來解析 rsync 日誌檔案或任何與此相關的內容,以告訴我已複製的檔案數量。這是我的 rsync 指令:
rsync -auvh --delete --progress "$SourceTx" "$Dest1Tx" --log file="$SourceRoot/""CopyLog1.txt"
我嘗試(不起作用)grep 日誌檔案來匯出複製的檔案數量:
cd "$SourceRoot/"
howMany=$(cat CopyLog1.txt | grep -c .mov)
osascript -e 'display notification "Transcode Copy Complete, '$howMany' files transfered, Log Files Created" with title "Transcode Copy Script"'
答案1
若要取得傳輸的檔案數,請使用該--stats
選項。例如:
$ rsync -auvh --stats --delete --log-file=1.log --progress "$SourceTx" "$Dest1Tx" | grep 'files transferred'
Number of regular files transferred: 21
要擷取傳輸到 shell 變數的檔案數:
nfiles=$(rsync -auvh --stats --delete --log-file=1.log --progress "$SourceTx" "$Dest1Tx" | awk '/files transferred/{print $NF}')
上面的內容經過過濾,僅顯示傳輸的檔案數量。為了說明可用的其他資訊--stats
:
$ rsync -auh --stats --delete srcdir destdir
Number of files: 14 (reg: 10, dir: 4)
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 0
Total file size: 209 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 342
Total bytes received: 27
sent 342 bytes received 27 bytes 738.00 bytes/sec
total size is 209 speedup is 0.57