scp 解除链接问题
scp 在传文件的时候会解除链接,当软链接指向的文件不存在时,scp 会报 no such file 的问题。
阅读 scp 命令帮助信息,确认 scp 不支持设定关闭解除链接功能。
新的问题
引出如下问题:
Is it possible to make SCP ignore symbolic links during copy?
如下链接中有多个解决方案:
Is it possible to make SCP ignore symbolic links during copy?
第一个解决方案
使用 rsync 命令,命令行如下:
rsync --progress -avhe ssh /usr/local/ XXX.XXX.XXX.XXX:/BackUp/usr/local/
相关选项的解释如下:
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
-l, --links copy symlinks as symlinks
第二个解决方案
tar cf - /usr/local/bin | ssh server.example.com tar xf -
针对这个问题的解释如下:
Although scp can copy directories, it isn’t necessarily the best method. If your directory contains hard links or soft links, they won’t be duplicated. Links are copied as plain files (the link targets), and worse, circular directory links cause scp1 to loop indefinitely. (scp2 detects symbolic links and copies their targets instead.) Other types of special files, such as named pipes, also aren’t copied correctly.A better solution is to use tar, which handles special files correctly, and send it to the remote machine to be untarred, via SSH
总结
建议使用第一种方案,如果系统中缺少 rsync 程序,则考虑使用第二种方式!