scp 解除链接问题的两个解决方案

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 程序,则考虑使用第二种方式!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值