Aug 24

rsync的坑 不指定

felix021 @ 2011-8-24 18:41 [IT » 软件] 评论(0) , 引用(0) , 阅读(7155) | Via 本站原创 | |
rsync是个好东西,同步文件很方便,等啥时候有空了,可以考虑把内核提供的inotify功能结合起来,搞一个实时文件同步的应用 :D

回归主题,说说这个坑,线上的机器用rsync来进行文件的同步。
$ rsync -az --delete /home/user/files/ user@remote_host:/home/user/files/
user@remote_host's password:
TERM environment variable not set.
protocol version mismatch -- is your shell clean?
(see the rsync man page for an explanation)
rsync error: protocol incompatibility (code 2) at compat.c(174) [sender=3.0.8]


从昨天到今天这个问题一直出现,不管是2.6.8还是最新的3.0.8,看了N个使用例子,最后结果都是这样。Boluor同学的建议是配置信任关系(ssh-keygen -t rsa; ssh-copy-id user@remote_host),但是这样只是不需要输入密码,并没有解决问题。

于是RTFW,Google了一下,发现在 http://ss64.com/bash/rsync.html 的DIAGNOSTIC 一节有说明, .bashrc 等启动脚本的任何输出,都会影响rsync通过ssh同步时的数据流,导致协议不匹配。

以这个命令为例:

$ ssh user@remote_host /bin/true > out.txt

实际上所有的动作是

1.  ssh 与 remote_host 的 sshd 交互
2. sshd fork出一个 user shell(一般是/bin/bash)
3. /bin/bash 载入 $USER/.bash_profile
4. .bash_profile一般会载入.bashrc
5. /bin/bash 执行/bin/true 并重定向stdin到out.txt

正常情况下,out.txt应该是一个空文件。如果在这个过程中有任何输出(比如我当时的.bashrc有一个echo),就会导致rsync在执行过程中的数据有额外的GARBAGE,出现问题。

OVER.



欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]