cwSync文件同步工具 linux window

来源:互联网 发布:美微柠檬免费网络电视 编辑:程序博客网 时间:2024/06/05 17:20

最近公司CRM做了集群,为了解决服务器之间的Web文件同步,体验了一把cwSync,感觉还不错,把在网上找的一些用法和自己摸索的一些方法写下:

rsync远程备份实测和总结
归纳如下:
1)拷贝本地文件:当本地和远程路径中不包含冒号":"分隔符时,就启用这种工作模式:# rsync -avzSH /home/cmail/ /cmbak/
2)使用rsh或ssh来实现将本地机器的内容拷贝到远程机器:当远程路径地址包括冒号":"分隔符时启动该模式;
# rsync -avzSH /home/cmail/ 192.168.1.219:/home/cmail/ 不带用户名默认用当前帐号。 3) 从远程rsync服务器中拷贝文件到本地,或本地复制到远程亦可:当SRC或DST路径信息包含"::"分隔符时启动该模式。
如:rsync -avroot@172.16.78.192::www/databack 注:www是主机上/etc/rsyncd.conf中配置组名。
4) 列出远程机的文件列表:这类似于rsync传输,不过只要在命令中省略掉本地机信息即可。如:
# rsync -v rsync://mysql@192.168.1.218:873/test --password-file=/etc/rsyncd.pwd【本地地址可略】仅列出远程主机的文件列表。test是远程

主机的/etc/rsyncd.conf中配置组名。

*************************************************************************************************
1、linux对linux备份:centos6.2
*************************************************************************************************

centos 6.2默认已安装rsync-3.0.6-5.el6_0.1.i686并以ssh方式运行。这里改用服务方式运行。
1、编辑配置文件/etc/xinetd.d/rsync  :把disable = yes 改为disable = no,注释掉flag = ipv6。修改好后,保存退出
2、手动创建配置文件#vi /etc/rsyncd.conf ,输入如下内容:
-----------------------------------------------------------
#如果不加这行strict modes = false,可能会出现@ERROR: auth failed on module mysql
strict modes = false
#只允许192.168.1.0 网段下的客户端同步,也可指定IP。www.linuxidc.com 多个IP用逗号且无空格连接,如192.168.1.2,192.168.1.3
#也可用:hosts deny = 0.0.0.0/32
hosts allow = 192.168.1.0/255.255.255.0
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid #指定rsync的pid文件,可不用。

#motd file = /etc/rsyncd.motd #欢迎信息文件名称和存放位置(此文件没有,可以自行添加)
#lock file = /var/run/rsync.lock #指定支持max connections参数的锁文件,默认值
#max connections = 10   # 最大连接数为10

[mysql]  #指定认证的备份模块名为mysql,在client端需要指定
#备份路径
path= /mysqldata/

#验证用户,这行如果不用,则可匿名访问,多个用户用逗号“,”分隔
#不建议用root。
auth users = mysql

#备份以什么用户ID和组ID进行,也可用root
#但建议用mysql用户去读,只要设置有足够权限的用户即可,不建议用root.
uid = mysql
gid = mysql

# 可以忽略一些无关的IO错误
ignore errors

#不允许列文件
list = no

#密码验证文件:username:password
secrets file = /etc/rsyncd.secrets

#关闭只读,可以上传
read only = no

#pid file = /var/run/rsyncd.pid
#log file = /var/log/rsyncd.log
#lock file = /var/run/rsync.lock
--------------------------------------------------------
说明:
auth users验证用户为root,auth users 是必须在服务器上存在的真实的系统用户,为了系统的安全一般不用root 用户,如果你想用多个用户,那就以“,”号隔开;比如 auth users = beinan , linuxsir
uid = root备份以什么身份进行,用户ID.
gid = root备份以什么身份进行,组ID.
注意这个用户ID 和组ID,如果要方便的话,可以设置成root,这样rsync 几乎就可以读取任何文件和目录了,但是也带来安全隐患。建议设置成只能读取

你要备份的目录和文件即可。
secrets file指定认证文件名,用来验证密码
read only关闭只读,允许客户端上传和下载

3、定义密码文件/etc/rsyncd.secrets
[root@cmmailapp2 data]# cat  /etc/rsyncd.secrets 
mysql:123456
4、修改密码权限:
[root@centos62 ~]# ll /etc/rsyncd.*
-rw-r--r--. 1 root root 300  3月  4 14:12 /etc/rsyncd.conf


-rw-r--r--. 1 root root  16  3月  4 14:13 /etc/rsyncd.secrets
[root@centos62 ~]# chmod 600 /etc/rsyncd.*
[root@centos62 ~]# chown mysql.mysql /etc/rsyncd.*

[root@centos62 ~]# ll /etc/rsyncd.*
-rw-------. 1 mysql mysql 300  3月  4 14:12 /etc/rsyncd.conf
-rw-------. 1 mysql mysql  16  3月  4 14:13 /etc/rsyncd.secrets

5、服务启动:
Rsync服务端启动有两种方法
(1)启动rsync服务端(独立启动)# /usr/bin/rsync --daemon  这里仅以这种方式启动。
(2)启动rsync服务端(用xinetd超级进程启动---centos6.2已不用)# /etc/init.d/xinetd reload  
    如果xinetd没有安装的话,先# yum install xinetd.

# rsync --daemon --config=/etc/rsyncd.conf

>>>设置开机自动启动rsync服务
# vi /etc/rc.local
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf #可不用--config选项,默认即读取/etc/rsyncd.conf
你也可以指定rsync运行的端口 #/usr/bin/rsync –daemon –port=873

记得配置防火墙,允许你rsync端口的tcp和udp协议。873:tcp 873:udp


[root@centos62 ~]#lsof -i :873
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rsync   3344 root    4u  IPv4  41928      0t0  TCP *:rsync (LISTEN)
rsync   3344 root    5u  IPv6  41929      0t0  TCP *:rsync (LISTEN)

至此,服务器端配置完成。

6、查看SELINUX是否打开端口,如果没有,则要打开。
[root@centos62 ~]# semanage port -p tcp -a -t rsync_port_t 873
[root@centos62 ~]# semanage port -l | grep rsync
rsync_port_t                   tcp      873
rsync_port_t                   udp      873

7、客户端安装:和服务端rsync安装的方法一样,两边的版本要相一致.
但客户端的增加一个密码文件/etc/rsyncd.pwd输入服务端/etc/rsyncd.secrets中密码部分如“123456”即可,注意不要添加用户名 。
注:密码验证文件设置的密码不一定是系统的密码,只要两边的密码一样就可以.
【注意】这份rsyncd.pwd文件必须设成#chmod 600 /etc/rsyncd.pwd,即仅属主可读的模式,
如果组和其它用户也可读,将会出错:password file must not be other-accessible

8、测试:【注意远程主机的格式是“用户名@主机::配置文件中的栏名”,如果不加用户名,默认同当前用户,不要用单冒号】
上传:[root@c62slave ~]# rsync -av  /root/pwd mysql@192.168.1.218::mysql
下载:[root@c62slave ~]# rsync -av mysql@192.168.1.218::mysql /root/mysqldata
不需手动输入密码:
上传:[root@c62slave ~]# rsync -av  /root/pwd mysql@192.168.1.218::mysql --password-file=/etc/rsyncd.pwd
下载:[root@c62slave ~]# rsync -vzrtopg --progress mysql@192.168.1.218::mysql /root/mysqldata/ --password-file=/etc/rsyncd.pwd

仅列出远程主机的文件清单:

# rsync -v rsync://wolf2012@192.168.1.218:873/test --password-file=/etc/rsyncd.pwd仅列出远程主机的文件列表。

test是远程主机的/etc/rsyncd.conf中配置组名。

9、创建一个脚本用来运行文件同步命令
#!/bin/bash
/usr/bin/rsync .......

[root@c62slave ~]#crontab -e 后略。


*************************************************************************************************
2、linux(服务器)对windows(客户端)备份:
*************************************************************************************************

windows下要用cwRsync软件,安装和用法参下文。
而rsync命令都是一样的。唯一差别是,在命令中,客户端保存路径要写成/cygdrive
/f/mysql5.5.16/cwRsync/cwRsyncClient/表示同步到本地F:/mysql5.5.16/cwRsync/cwRsyncClient/目录下
注意,客户端为WINDOW不能用--password-file这个选项,目前尝试多种方案均未解决。
F:mysql5.5.16cwRsyncICWBin>rsync -av mysql@192.168.1.218::mysql /cygdrive
/f/mysql5.5.16/cwRsync/cwRsyncClient/

选项--password-file=/cygdrive/f/mysql5.5.16/cwRsync/client.pwd在WINDOW没用,依然要输入密码,参【常见错误】。

*************************************************************************************************
3、windows对windows备份:
*************************************************************************************************
安装cwRsync 4.0.6 服务端,客户端不需要安装。
安装目录F:mysql5.5.16cwRsync下名为ICW,其下的bin/rsync即可运行客户端
按如下配置文件即可。

配置文件:注意uid和gid的要用0,和LINUX不同。
uid = 0
gid = 0
use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log

# Module definitions
# Remember cygwin naming conventions : c:work becomes /cygwin/c/work
# [test]可以自定义,如可以定义[web],在客户端命令调用直接192.168.1.100::web表示使用该组 。 
[test]

#=================================
#默认生成的。
#=================================

#同步f盘f:/mysql5.5.16/cwRsync/rsynctest目录下的所有文件
path = /cygdrive/f/mysql5.5.16/cwRsync/rsynctest

#关闭只读功能,允许客户端上传和下载文件
read only = false

#打开日志功能
transfer logging = yes

#=================================
#以下为自己添加的。非cwRsync生成。
#=================================
# 最大连接数为4
#max connections = 4
# 可以忽略一些无关的IO错误
#ignore errors

#只允许192.168.1.0 网段下的客户端同步
#hosts allow = 192.168.1.0/255.255.255.0
#允许连接IP,多个IP中间用英文状态下逗号隔,不限制IP填写 *即可

#验证用户,安装时建的cwRsync,密码123456,也可用Administrator
#如果没有这行,则表明是匿名,客户端不需要输入密码。
auth users = cwRsync

#在C 盘的根目录下用记事本建立一个rsyncd.secrets 文件, 
#输入内容为cwRsync:123456,服务器的用户名和密码,该文件用来验证客户端同步文件的真实性。
secrets file = /cygdrive/f/mysql5.5.16/cwRsync/rsyncd.secrets

-----------------------------------------------------------------------------
命令测试:
上传:
F:mysql5.5.16cwRsyncICWBin>rsync -av /cygdrive/f/mysql5.5.16/cwRsync/cwRsync
Client/ cwRsync@192.168.1.100::test
Password:《==要手动输入密码。
sending incremental file list  #以下都是传输的测试文件。
./
新建 文本文档.txt
新建文件夹/

sent 149 bytes  received 34 bytes  52.29 bytes/sec
total size is 11  speedup is 0.06


下载:
F:mysql5.5.16cwRsyncICWBin>rsync -av cwRsync@192.168.1.100::test /cygdrive/f
/mysql5.5.16/cwRsync/cwRsyncClient/
Password:《==要手动输入密码。
receiving incremental file list
./
arsynctest.rar
client.txt
rsynctest是服务器端.doc
rsynctest是服务器端的内容.txt

sent 136 bytes  received 11161 bytes  4518.80 bytes/sec
total size is 10790  speedup is 0.96

F:mysql5.5.16cwRsyncICWBin>
-----------------------------------------------------------------------------
要注意路径的斜杠。很重要!!!
/cygdrive/c/work/ Administrator@192.168.1.31::test
这个写法, 会吧 c:/ 盘下work 文件夹下的所有文件都同步到服务器c:/work
当前目录下边
/cygdrive/c/work Administrator@192.168.1.31::test
这个work 后少了个斜杠!, 就会把c:/ 盘下work 文件同步到服务器当前目录
下边c:/work 的文件内就是说他会再建一个文件夹。


*************************************************************************************************
4、常见错误:
*************************************************************************************************

错误1:
在最后带上--password-file=/cygdrive/f/mysql5.5.16/cwRsync/pwd.secrets时,提示:


password file must not be other-accessible
continuing without password file
Password:
网上答案是:WINDOW出现这种情况,是因为pwd.secrets的权限不对,或存放的位置不是NTFS分区。但二者均检验过,仍无效。
尝试了:
A、用/cygdrive/f...
B、路径改成f:/和f:,
C、把--password-file选项放前面或后面
D、把pwd.secrets的属性安全只保留WINDOWS帐户或cwRsync,且只读。
E、把linux其它客户端上的rsyncd.pwd拖下来给window也不行。
四种情况均无效。有待进一步尝试。
在linux上出现这种错误则容易解决。原因是这份客户端的密码文件必需设成调用者只读属性“600”才行。


错误2: 
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(794) [receive
r=3.0.2]
解决:很大可能是服务器端没有开启 rsync 服务。开启服务。



错误3:
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解决:服务器端同步目录没有权限,cwrsync 默认用户是Svcwrsync。为同步
目录添加用户Svcwrsync 权限。



错误4:
rsync: failed to connect to 210.28.93.4: No route to host (113)
是server端口的防火墙端口没开。



错误5:
@ERROR: chroot failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6] 
是服务器上忘记新建目录了…



错误6:
rsync warning: some files vanished before they could be transferred (code 24) at main.c(1039) [sender=3.0.6]
本地文件在同步过程中被删除了。



错误7:
rsync error: some files could not be transferred (code 23) at main.c(1385) [generator=2.6.9] 
这是因为在服务器端的备份文件名中有非法符号,可能造成Windows同步数据时无法识别文件名。



错误8:
@ERROR: failed to open lock file
rsync error: error starting client-server protocol (code 5) at main.c(1495) [rec
eiver=3.0.2]
解决:配置文件 rsync.conf 中添加 lock file = rsyncd.lock 即可解决。



错误9:
@ERROR: auth failed on module XXX
出现这种情况,先检查你的用户名、密码、主机IP地址是否正确,
如果都正确,有一个可能是原因是:远程rsync服务器的帐户密码文件的权限必须为600,例如,你在rsyncd.conf中设置了secrets file =

/etc/rsyncd/rsync_pwd
那么你就必须确保rsync_pwd的访问权限为600:
chmod 600 /etc/rsyncd/rsync_pwd
然后你的问题可能就解决了。

常见错误:

错误一
rsync: failed to connect to 96.44.169.178 (*inet_ntop failed*): Connection timed
out (116)
     1 [main] rsync 3468 exception::handle: Exception: STATUS_ACCESS_VIOLATION
   740 [main] rsync 3468 open_stackdumpfile: Dumping stack trace to rsync.exe.s
tackdump
1,防火墙问题
2,端口不对

错误二
@ERROR: auth failed on module www
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Rec
eiver=3.0.8]
密码不对

错误三
@ERROR: invalid uid nobody
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Rec
eiver=3.0.8]
UID不对,默认是nobody
解决方法:
uid = 0
gid = 0

错误四
receiving incremental file list
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(769) [receive
r=3.0.8]
rsync: connection unexpectedly closed (60 bytes received so far) [generator]
rsync error: error in rsync protocol data stream (code 12) at io.c(610) [generat
or=3.0.8]
可能原因:
1,磁盘挂载是用异步的(async)
然后,检查了/etc/fstab ,去掉async参数。

2,我在服务器上查看日志,看到有这么一行:
rsync: unable to open configuration file "/etc/rsyncd.conf": No such file or directory

于是我:
ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf

3,同步文件数较多的目录出错
有个子目录中文件较多,也就8000来个吧,总是同步一半便退出。在批处理中加上-v参数,看到错误信息如下:
rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Connection reset by peer (104)
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(768) [sender=
3.0.6]

这个问题有点头疼,在www.itefix.no网站论坛上也没能查出个所以然。

不过最终还是在samba.org上找到解决方案:

在客户端命令行中加上--no-iconv参数就可以了。

原以为是文件太多,缓冲区不够引起,但看这个解决方案,似乎是转换编码方面的bug了。

在rsync的文档中描述如下:
http://rsync.samba.org/ftp/rsync/rsync.html
--iconv=CONVERT_SPEC
Rsync can convert filenames between character sets using this option. Using a CONVERT_SPEC of "." tells rsync to look up the default character-set via the locale setting. Alternately, you can fully specify what conversion to do by giving a local and a remote charset separated by a comma in the order --iconv=LOCAL,REMOTE, e.g. --iconv=utf8,iso88591. This order ensures that the option will stay the same whether you're pushing or pulling files. Finally, you can specify either --no-iconv or a CONVERT_SPEC of "-" to turn off any conversion. The default setting of this option is site-specific, and can also be affected via the RSYNC_ICONV environment variable.



五、问题排除及注意事项
问题排除:
1、问题1
rsync: read error: Connection reset by peer (104)

rsync error: error in rsync protocol data stream (code 12) at io.c(614) [receiver=2.6.8]

解决:在服务器上查看日志,看到有这么一行:

rsync: unable to open configuration file “/etc/rsyncd.conf”: No such file or directory

于是执行如下命令:

[root@bogon ~]# ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf
但是继续报如下错误:

sending incremental file list

ERROR: module is read only

rsync error: syntax or usage error (code 1) at main.c(879) [Receiver=3.0.8]

rsync: read error: Connection reset by peer (104)

rsync error: error in rsync protocol data stream (code 12) at io.c(760) [sender=3.0.8]
到备份服务器上修改主配置文件

[root@bogon ~]# vim /etc/rsyncd/rsyncd.conf



read only=yes

改为

read only=no

问题解决,实现单向同步
2、问题2
[root@www backup]# rsync -vzrtopg –progress –delete promise@172.16.10.189::promise /home/bak/

Password:

@ERROR: chdir failed

rsync error: error starting client-server protocol (code 5) at main.c(1516) [Receiver=3.0.8]

解决:目录设置错误
确定配置文件里的目录正确
3、问题3
在Linux下使用rsync同步时,出现以下错误:
@ERROR: auth failed on module bakup
其中,bakup是rsync服务模块名称。
出现这种情况,先检查了用户名和密码正确性,经检查无误,排除了这个可能性,另外可能的原因是:rsync服务器的帐户密码文件的权限没有设置为600,修改/etc/rsyncd/rsyncd.secrets文件:
[root@bogon ~]#

chmod 600 /etc/rsyncd/rsyncd.secrets

问题解决。
4、问题4
在备份路径后面一定要加“/”,否则在双向同步时会一直循环同步。如:
src=/var/www/  //后面一定要加“/”
5、问题5
同步mysql数据时需要注意:
本地源主机(H1)是一台web服务器,把/var/lib/mysql备份到备份服务器(H2),当web服务器上的数据受损时需要从备份服务器把数据同步到web服务器
执行脚本文件:/usr/local/sbin/rsync.sh
同步备份服务器上的/var/lib/mysql到web服务器后仍然无法访问网站,此时需要重启mysql
#/etc/init.d/mysqld restart
问题解决。

网上相关资料:
资料一:
最近在配置rsync服务器镜像备份。中间遇到@ERROR: auth failed on module  这个问题,网上找了好多资料,也具体对照测试了。

   1、

   [root@bo bin]# /usr/local/rsync/bin/rsync -vazu -progress –delete backup@192.168.1.238::www /tmp –password-file=/etc/backserver.pas

   rsync: Failed to exec ss: No such file or directory (2)

   rsync error: error in IPC code (code 14) at pipe.c(86) [receiver=2.6.9]

   rsync: writefd_unbuffered failed to write 12 bytes [receiver]: Broken pipe (32)

   rsync error: error in rsync protocol data stream (code 12) at io.c(1122) [receiver=2.6.9]

   [root@ht-store bin]#

   以上错误可能是上面使用的参数前面的符号不正确。换成下面的就没有上面的错误了

   [root@bo /]# usr/local/rsync/bin/rsync -vzrtopgu –progress –delete –password-file=/etc/backserver.pas backup@192.168.1.238:www /tmp

   2、

   [root@ht-store /]# usr/local/rsync/bin/rsync -vzrtopgu –progress –delete backup@192.168.1.238:www /tmp/ –password-file=/etc/backserver.pas

   backup@192.168.1.238′s password:

   Permission denied, please try again.

   backup@192.168.1.238′s password:

   Permission denied, please try again.

   backup@192.168.1.238′s password:

   Permission denied (publickey,gssapi-with-mic,password).

   rsync: connection unexpectedly closed (0 bytes received so far) [receiver]

   rsync error: unexplained error (code 255) at io.c(453) [receiver=2.6.9]

   [root@ht-store /]#

   更改成

   [root@ht-store /]# usr/local/rsync/bin/rsync -vzrtopgu –progress –delete –password-file=/etc/backserver.pas
 backup@192.168.1.238::www /tmp

   @ERROR: auth failed on module www

   rsync error: error starting client-server protocol (code 5) at main.c(1383) [receiver=2.6.9]

   [root@ht-store /]#

   3、

   [root@ht-store /]# /usr/local/rsync/bin/rsync -vazu –progress –delete –password-file=/etc/backserver.pas

   backserver@192.168.1.238::www /tmp

   @ERROR: auth failed on module www

   rsync error: error starting client-server protocol (code 5) at main.c(1383) [receiver=2.6.9]

   检查一下用户名是否错误backserver 应该是backup

   4、

   [root@ht-store /]# /usr/local/rsync/bin/rsync -vzar –progress –delete –password-file=/etc/backserver.pas backup@192.168.1.238:www /tmp

   backup@192.168.1.238′s password:

   Permission denied, please try again.

   backup@192.168.1.238′s password:

   rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(244) [receiver=2.6.9]

   是双引号“::”backup@192.168.1.238::www  而不是单引号“:”backup@192.168.1.238:www

   5、

   [root@ht-store /]# /usr/local/rsync/bin/rsync -vzrtopgu –progress –delete –password-file=/etc/backserver.pas backup@192.168.1.238::www /tmp

   @ERROR: Unknown module ‘www’

   rsync error: error starting client-server protocol (code 5) at main.c(1383) [receiver=2.6.9]

   这是因为服务器端hosts allow 没有允许该主机访问
资料二:
  1. Q: 出現以下這個訊息, 是怎麼一回事?

   @ERROR: auth failed on module xxxxx

   rsync: connection unexpectedly closed (90 bytes read so far)

   rsync error: error in rsync protocol data stream (code 12) at io.c(150)

   A: 這是因為密碼設錯了, 無法登入成功, 請再檢查一下 rsyncd.pwd ,rsyncd.sec中的密碼設定, 二端是否一致?有时服务器

   端没有起动服务也会出现这种情况

   2. Q: 出現以下這個訊息, 是怎麼一回事?

   password file must not be other-accessible

   continuing without password file

   Password:

   A: 這表示 rsyncd.pwd rsyncd.sec 的檔案權限屬性不對, 應設為 600

   請下 chmod 600 rsyncd.pwd rsyncd.sec

   3. Q: 出現以下這個訊息, 是怎麼一回事?

   @ERROR: chroot failed

   rsync: connection unexpectedly closed (75 bytes read so far)

   rsync error: error in rsync protocol data stream (code 12) at io.c(150)

   A: 這通常是您的 rsyncd.conf 中

   的 path 路徑所設的那個目錄並不存在所致.

   請先用 mkdir 開設好備份目錄.

   4.Q:出现一下信息是怎么回事

   rsync: failed to connect to 218.107.243.2: No route to host (113)

   rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]

   所以情況會是:

   1. 對方主機沒開機

   2. 對方有 firewall 阻擋

   3. 所通過的網路上有 firewall 阻擋

   shell>setup   #关闭防火墙,其实最重要的也就是把tcp udp 的873端口打开。

   5.Q:出现一下信息是怎么回事

   当

   /server/rsync/bin/rsync -vzrutogp –progress –password-file=/etc/rsyncclien

   t.pwd backup@60.173.7.35:backup /var/www/backup

   出现

   backup@60.173.7.6′s password

   Permission denied, please try again.
  最有可能的情况是,系统没有认出来,你现在的通信是rsync,所以请仔细检查一下上面加红的那句话中ip地址后面是否为两个:也就是说::为rsync通信,:为ssh通信

   6.Q:

   当/server/rsync/bin/rsync rsync://backup@61.156.238.119/backup时,出现如下

   rsync: link_stat “/.” (in backup) failed: Permission denied (13)

   rsync error: some files could not be transferred (code 23) at main.c(1385) [receiver=2.6.9]

   解决方法:更改你的rsyncd.conf中的

   uid=nobody

   gid=nobody

   为

   uid=root

   gid=root
  解决方法2

   出现这样问题的原因是我要同步的这个root目录在掩位的最后一位
   不是r-x或以上的权限,也就是说root这个目录一定要等于或大于drwxr-xr-x才能同步。
附录一:源主机和备份服务器的配置文档
源主机配置文件 
见附件<rsync.sh>、<rsyncd.pass>
备份服务器配置文件
见附件<rsyncd.conf>、<rsyncd.motd>、<rsyncd.secrets>
附录二:Rsync的INSTALL文档
见附件<INSTALL_Rsync>
附录三:Inotify的INSTLL文档
见附件<INSTALL_Inotify>

注意,有时候安装时会出点末知原因,例如,不能程序本身没有注册服务,可以通过好动方式:
C:ICWbin>cygrunsrv.exe -I "Rsync" -p "/cygdrive/C/ICW/bin/rsync.exe" -a "--config=/cygdrive/C/ICW/rsyncd.conf --daemon --no-detach" -f "Rsync"

*************************************************************************************************
5、常用选项:
*************************************************************************************************

-vzrtopg --delete是常用选项。
【-u选项可以保障当从机有更新过同名文件时,不会在同步时被主机更改。】


【--delete如果想保持客户端和服务端真正同步,应使用此选项,这样服务端删掉某文件时,客户端也会删掉】
【-e ssh如果想用ssh传输,则应加此选项】
-a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
-v, --verbose 详细模式输出
-q, --quiet 精简输出模式
-c, --checksum 打开校验开关,强制对文件传输进行校验
-r, --recursive 对子目录以递归模式处理
-R, --relative 使用相对路径信息
-b, --backup 创建备份,即对目的已经存在有同名文件时,将老的文件重新命名为~filename。可以使用--suffix 选项来指定不同的备份文件前缀
--backup-dir 将备份文件(如~filename)存放在在目录下。
-suffix=SUFFIX 定义备份文件前缀
-u, --update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件。(不覆盖更新的文件)【重要】
-l, --links 保留软链结
-L, --copy-links 想对待常规文件一样处理软链结
--copy-unsafe-links 仅仅拷贝指向SRC 路径目录树以外的链结
--safe-links 忽略指向SRC 路径目录树以外的链结
-H, --hard-links 保留硬链结
-p, --perms 保持文件权限
-o, --owner 保持文件属主信息
-g, --group 保持文件属组信息
-D, --devices 保持设备文件信息
-t, --times 保持文件时间信息
-S, --sparse 对稀疏文件进行特殊处理以节省DST 的空间
-n, --dry-run 现实哪些文件将被传输
-W, --whole-file 拷贝文件,不进行增量检测
-x, --one-file-system 不要跨越文件系统边界
-B, --block-size=SIZE 检验算法使用的块尺寸,默认是700 字节
--password-file=/password/path/file指定密码文件,这样可以在脚本中使用而无需交互式地输入验证密码了,需要注意的是这份密码文件权限属性要设得只有属主可读。chmod 600 /etc/rsyncd.pwd
-e, --rsh=COMMAND 指定使用rsh、ssh 方式进行数据同步
--rsync-path=PATH 指定远程服务器上的rsync 命令所在路径信息
-C, --cvs-exclude 使用和CVS 一样的方法自动忽略文件,用来排除那些不希望
传输的文件
--existing 仅仅更新那些已经存在于DST 的文件,而不备份那些新创建的文件
--delete-excluded 同样删除接收端那些被该选项指定排除的文件
--delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。【慎用】
--delete-after 传输结束以后再删除
--ignore-errors 及时出现IO 错误也进行删除
--max-delete=NUM 最多删除NUM 个文件
--partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输
--force 强制删除目录,即使不为空
--numeric-ids 不将数字的用户和组ID 匹配为用户名和组名
--timeout=TIME IP 超时时间,单位为秒
-I, --ignore-times 不跳过那些有同样的时间和长度的文件
--size-only 当决定是否要备份文件时,仅仅察看文件大小而不考虑文件时间
--modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0
-T --temp-dir=DIR 在DIR 中创建临时文件
--compare-dest=DIR 同样比较DIR 中的文件来决定是否需要备份
-P 等同于 --partial
--progress 显示备份过程
-z, --compress 对备份的文件在传输时进行压缩处理
--exclude=PATTERN 指定排除不需要传输的文件模式
--include=PATTERN 指定不排除而需要传输的文件模式
--exclude-from=FILE 排除FILE 中指定模式的文件
--include-from=FILE 不排除FILE 指定模式匹配的文件
--version 打印版本信息
--address 绑定到特定的地址
--config=FILE 指定其他的配置文件,不使用默认的rsyncd.conf 文件
--port=PORT 指定其他的rsync 服务端口
--blocking-io 对远程shell 使用阻塞IO
--stats 给出某些文件的传输状态
--progress 在传输时现实传输过程
--log-format=formAT 指定日志文件格式

下面是我自己用的一段小代码
cd "C:Program FilesICWbin"
c:
rsync.exe -ravz --progress Balance@158.161.58.13::CRM61 --port 18910 /cygdrive/D/CRM61/Library/ <D:CRM61a.txt
rsync.exe -ravz --progress Balance@158.161.58.26::CustomPages --port 18910 /cygdrive/D/Sage/CRM/MetenCRM/WWWRoot/CustomPages/ <D:CRM61a.txt

本文出自 “生命不止,战斗不息!” 博客,请务必保留此出处http://soulful.blog.51cto.com/468033/1045579

0 0
原创粉丝点击