如果中止,则恢复文件传输

时间:2016-08-08 19:06:12

标签: bash unix rsync scp

我使用rsync或scp传输非常大的文件。 有时转移被中止所以我需要监控它并手动恢复它。 你能帮我写一个脚本,它将恢复已中止或已完成的文件传输,但文件(源和目标)的大小不同(在这种情况下,传输将从头开始重新启动 - 首先它将删除目标文件和传输将重新启动)。 有一点要提到的是,当我连接到源服务器时,我需要提供密码,所以我希望密码是脚本的参数

1 个答案:

答案 0 :(得分: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.

所以如果你想同步(继续同步)目录:

sudo rsync -azvvP /home/path/folder1/ /home/path/folder2

您可以在此处找到一些额外的信息:

要自动恢复,只需循环运行:

RETRY_IN=5
while rsync -azvvP /home/path/folder1/ /home/path/folder2
do
   echo "Retrying in ${RETRY_IN} sec"
   sleep "${RETRY_IN}"
done
相关问题