昨天写了篇《Win用rsync通过免密ssh登录同步文件到linux》,文中描述了windows安装cwRsync和免密码登录linux的环境配置,在测试同步的过程发现几个比较容易忽略的问题,今天总结一下。
一、任意路径执行rsync:找不到rsync.exe的问题;
尝试将rsync.exe所在路径【D:\tools\cwRsync5.5.0\bin\】加入系统变量path中,问题依旧;
解决办法:
使用完整路径即可解决;
命令:D:\tools\cwRsync5.5.0\bin\rsync.exe --version 查看rsync版本;
二、rsync通过ssh连接远程主机的时候需指定ssh.exe的路径,不指定则出错:
rsync: Failed to exec ssh: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(85) [Receiver=3.1.2]
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [Receive
r=3.1.2]
从报错第一句看来确实是没有找到ssh.exe而导致无法连接远程服务器,使用如下几条命令均正常:
rsync -e ./ssh.exe root@192.168.1.5:
rsync -e D:\tools\cwRsync5.5.0\bin\ssh.exe root@192.168.1.5:
D:\tools\cwRsync5.5.0\bin\rsync.exe -e D:\tools\cwRsync5.5.0\bin\ssh.exe root@192.168.1.5:
D:\tools\cwRsync5.5.0\bin\rsync.exe -e "D:\tools\cwRsync5.5.0\bin\ssh.exe" root@192.168.1.5:
C:\Documents and Settings\Administrator>D:\tools\cwRsync5.5.0\bin\rsync.exe -e "D:\tools\cwRsync5.5.0\bin\ssh.exe" root@192.168.1.5:
三、查看远程主机默认路径的时候如上面的三条命令容易忽略后边的冒号:
如上图报错,没有冒号会认为是本地路径;
四、本地路径的表示:
/cygdrive/d/test/wwwroot/
表示D:\test\wwwroot目录;
/cygdrive/d/"Program Files"/
表示D:\Program Files,带空格的目录用双引号引起来;
D:\tools\cwRsync5.5.0\bin>rsync /cygdrive/d/"Program Files"/
drwxrwx--- 0 2016/07/06 16:48:01 .
drwxrwx--- 0 2016/07/05 09:04:39 Java
drwxrwx--- 0 2015/05/08 16:40:58 Microsoft SQL Server
drwxrwx--- 0 2016/07/05 08:44:51 Mozilla Firefox
drwxrwx--- 0 2016/07/06 16:49:16 Nmap
【最后总结】细节决定成败,任何看似简单的东西,当真正去使用的时候会发现正是一些小细节的问题,导致出错不断。
本文暂时没有评论,来添加一个吧(●'◡'●)