Linux如何遠端拷貝,限速和斷點續傳

scp命令 – 遠端拷貝檔案

scp 拷貝本地檔案filename 到遠端機器 192.168.188.188 伺服器的/data/tmp目錄下

scp -P 61204 -l 40000 filename [email protected]:/data/tmp/

  • -P port
       Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’, because -p is already reserved for preserving the times and modes of the file in rcp(1).
  • #-P 指定遠端伺服器ssh服務的埠 如:ssh埠為61204
  • -l limit Limits the used bandwidth, specified in Kbit/s.
  • -l 指定拷貝的速度限制 單位是ct/s 如:-l 40000 表示40000Kbit/s=40000/8KB=5MB的速度
  • 注:scp不支援斷點續傳

    rsync ssh 斷點續傳

    #rsync同步本地檔案 filename 到遠端機器 192.168.188.188 伺服器的/data/tmp目錄下

    rsync -avzP -e 'ssh -p 61204' --bwlimit=5000 filename [email protected]:/data/tmp/ >> scp_to_101.log

  • -a:以archive模式操作,複製目錄、符號連線,等價於 -rlptgoD 。
  • -v:詳細提示
  • -z:壓縮
  • -P:是綜合了--partial --progress兩個引數
  • --partial
       如果在拷貝檔案的過程中,傳輸被中斷,rsync的預設操作是撤消前操作,即從目標機上刪除已拷貝的部分檔案。
       如果想在下次拷貝時續傳檔案,不需要重新拷貝所有檔案的話,可以使用-partial選項阻止rsync在傳輸中斷時刪除已拷貝的部分
  • --progress 顯示進度條
  • -e:引數的作用是可以使使用者自由選擇欲使用的shell程式來連線遠端伺服器
  • ssh -p 61204

    指定ssh的埠(非預設22)61204

  • --bwlimit: --bwlimit=5000 限制頻寬為5000k Bytes/s =5MB
  • 上例:使用rsync傳輸本地檔案filename到192.168.188.188的/data/tmp目錄下 使用壓縮歸檔傳輸、限速5MB、支援斷點續傳 使用ssh協議