说明:
本篇文章实现linux定时将www,msyql,svn目录rsync到win2003指定目录上。
win2003安装CWRsync,做为rsync的server端,运行CWRsync守护进程daemon,接受linux同步过来的文件;
linux为centos,本身就有rsync,按时rsync文件到win上。
环境:
win2003 192.168.1.2 CWRsync rsyncd服务端,以daemon守护进程运行
linux 192.168.1.3 rsync客户端
实现:
1.win2003安装CWRsync及防火墙设置
请参照:CWRsync图文安装
2.修改CWRsync配置文件rsyncd.conf(CWRsync安装目录下,我这里的安装目录是:D:CWRsync)
uid = 0 gid = 0 use chroot = false strict modes = false hosts allow = 192.168.1.3 log file = rsyncd.log # Module definitions # Remember cygwin naming conventions : c:work becomes /cygwin/c/work # [www] path = /cygdrive/e/bakup/1_3/www //CWRsync会自动将系统上所有的盘mount成/cygwin/x,因此/cygdrive/e/bakup/1_3/www指的是e:bakup1_3www目录 read only = false transfer logging = yes auth users = rsyncd secrets file = /cygdrive/D/CWRsync/rsyncd.secrets [mysql] path = /cygdrive/e/bakup/1_3/mysql read only = false transfer logging = yes auth users = rsyncd secrets file = /cygdrive/D/CWRsync/rsyncd.secrets [svn] path = /cygdrive/e/bakup/1_3/ read only = false transfer logging = yes auth users = rsyncd secrets file = /cygdrive/D/CWRsync/rsyncd.secrets
3.添加CWRsync密码文件D:CWRsyncrsyncd.secrets
rsyncd:rsyncd //用户:密码
以上都是win2003的操作,下面是linux下的操作
4.添加rsync密码文件,这样linux定时rsync目录到win2003时就不需要输入密码
# cat /root/rsyncd.secrets rsyncd //直接输入密码
5.修改crontab,定时激发rsync同步
# crontab -e //添加以下内容 10 3 * * * rsync -vrlptD --progress --password-file=/root/rsyncd.secrets /home/www/data rsyncd@192.168.45.2::www 25 3 * * * rsync -vrlptD --progress --password-file=/root/rsyncd.secrets /home/mysql/data rsyncd@192.168.45.2::mysql 40 3 * * * rsync -vrlptD --progress --password-file=/root/rsyncd.secrets /home/svn rsyncd@192.168.45.2::svn
附录:
附录1.在linux端运行# rsync -avrtopg –progress –password-file=/root/rsyncd.secrets /home/www/data rsyncd@192.168.45.2::rsyncd会出现password file must not be other-accessible
continuing without password file
password:
问题password file must not be other-accessible已经回答了,保存密码的文件/root/rsyncd.secrets不应该被其它用户可读。
# chmod 600 /root/rsyncd.secrets //修改权限为600即可