2016-08-08 58 views
-1

我使用rsync或scp傳輸非常大的文件。 有時候傳輸被中止,所以我需要監視它並手動恢復。 你能幫我寫一個腳本,它將恢復已中止或已完成的文件傳輸,但文件(源和目標)的大小不一樣(在這種情況下,傳輸將從頭開始 - 首先它將刪除目標文件和傳輸將重新啓動)。 有一點要提到的是,當我連接到源服務器我需要提供一個密碼,所以我想密碼是一個參數的腳本恢復文件傳輸如果中止

回答

2

您需要-P--partial選項。

從手冊頁:

--partial By default, rsync will delete any partially transferred file if the transfer 
     is interrupted. In some circumstances it is more desirable to keep partially 
     transferred files. Using the --partial option tells rsync to keep the partial 
     file which should make a subsequent transfer of the rest of the file much faster. 

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

所以,如果你想要同步(continu同步)目錄:

你可以在這裏找到一些其他的相關信息:

要自動恢復它,只需在循環中運行它:

RETRY_IN=5 
while rsync -azvvP /home/path/folder1/ /home/path/folder2 
do 
    echo "Retrying in ${RETRY_IN} sec" 
    sleep "${RETRY_IN}" 
done 
+0

好的。我怎樣才能使RSYNC或SCP自動恢復傳輸(傳輸中止而不是用戶)? –

+0

@MichaelNathanSellers:從一個循環開始。查看我的更新 –