rsync
我使用以下命令在两台服务器之间运行命令:
rsync -auv -P --delete --delete-excluded --stats --progress -e "ssh -i ~/.ssh/$ssh_pkey -p $port -l $user" $server_ip:$src/ $dest/
在某个阶段,源服务器上的 HDD 发生故障,其安装点变得无法访问。这发生在rsync
指挥期间。不幸的是,我的目标文件夹中的所有文件都被删除,而命令--ignore-errors
中没有选项rsync
。
这是日志:
rsync: read errors mapping "/data/TEST1/file.tmp": Input/output error (5)
rsync: send_files failed to open "/data/TEST1/file.tmp": Input/output error (5)
.............
rsync: opendir "/data/TEST1/Stranger Things" failed: Input/output error (5)
rsync: send_files failed to open "/data/TEST1/file2.tmp": Input/output error (5)
3,511,822,850 100% 1.84MB/s 0:30:18 (xfr#36, ir-chk=1013/7161)
WARNING: TEST1/file.tmp failed verification -- update discarded (will try again).
deleting TEST1/file3.tmp
deleting ...
deleting ...
deleting ...
....
注意到 I/O 错误后,rsync 命令继续删除所有残留文件!
这是一个非常危险的情况。到目前为止,还没有造成任何损害,因为我只需重新安装 HDD,重新启动 rsync(这将需要几天时间),但下次我可能不会那么幸运。
究竟出了什么问题?如何防止这种情况发生?
答案1
这是参数的预期行为--delete
。您可以--delete-after
等待传输完成后再删除不需要的文件。
man rsync
...
--del an alias for --delete-during
--delete delete extraneous files from dest dirs
--delete-before receiver deletes before xfer, not during
--delete-during receiver deletes during the transfer
--delete-delay find deletions during, delete after
--delete-after receiver deletes after transfer, not during
--delete-excluded also delete excluded files from dest dirs
--ignore-missing-args ignore missing source args without error
--delete-missing-args delete missing source args from destination
--ignore-errors delete even if there are I/O errors
...