需求:需要把A服务器上的某些数据定期备份到B服务器中


A服务器:

#yum install -y rsync

#rpm -qa | grep rsync

#vim /etc/xinetd.d/rsync

         yes改成no  ,开启 rsync

#chkconfig rsync on                  

#chkconfig --list rsync

 

生成配置文件

#vim /etc/rsyncd.conf

         uid= root

         gid= root

         port= 873                                                       默认端口873

         hostsallow = 10.10.50.31                          允许主机

        

         pidfile = /var/run/rsyncd.pid

         lockfile = /var/run/rsync.lock

         logfile = /var/log/rsyncd.log

 

         [jichuang]                                                        模块参数

         path= /test/backup/                                    要同步的目录

         comment= rsync test!                                注释

         ignoreerrors                                                  忽略IO错误

         readonly = yes                                              是否只读

         list= no                                                            不允许列文件

         authusers = rsync                                        认证用户名

         secretsfile = /etc/rsync.passwd               认证用户名对应密码存放位置

 

创建认证文件

#vim /etc/rsync.passwd

         rsync:123456

#chmod 600 /etc/rsync.passwd

 

防火墙

iptables -A INPUT -p tcp --dport873 -j ACCEPT

 

启动服务

#netstat -ntlp | grep 873

#/usr/bin/rsync --daemon

 

 

B服务器

/usr/bin/rsync -vzrtopg --progress --deletersync@10.10.50.30::jichuang /test/back/

输入密码,即可抓取A服务器指定目录的文件,下载到本地 /test/back目录中

反之上传

# /usr/bin/rsync -vzrtopg --progress /home/backuprsync@10.10.50.30::jichuang

 

B服务器同步免输入密码

# vim /etc/rsync.passwd

 123456

# chmod 600 /etc/rsync.passwd

#/usr/bin/rsync -vzrtopg --progress--delete --password-file=/etc/rsync.passwd rsync@10.10.50.30::jichuang/test/back/

 

 

 

自动运行

# vim /root/rsync.sh

         #!/bin/bash

         /usr/bin/rsync-vzrtopg --progress --delete --password-file=/etc/rsync.passwd  rsync@10.10.50.30::jichuang /test/back/

 

# crontab -e

*/10 * * * *    /root/rsync.sh                                   每隔10分钟执行一次