rsync实现同步

一、备份客户端:

1.创建/etc/rsyncd.secrets 权限配置600 (写服务器端的账户密码)

2.客户端配置文件:

port=873
log file=/var/log/rsync.log
pid file=/var/run/rsync.pid
hosts allow =172.16.16.231
hosts deny=*

[backup]           
path=/databackup                (本机的备份用的文件夹)
use chroot=yes 
max nonections=4
read only=no
list=yes
uid=root
gid=root
#auth users=root
secrets file=/etc/rsyncd.secrets

启动rsync :  rsync --daemo --config=/etc/rsyncd.conf

备份服务端

创建/etc/rsyncd.secrets 权限配置600 (写服务器端的账户密码)

服务端配置文件:

port=873
log file=/var/log/rsync.log
pid file=/var/run/rsync.pid
hosts allow=172.16.16.160
hosts deny=*
[abc]
path=/databakup                  (本机的要备份用的文件夹)
use chroot=yes
max nonections=4
read only=no
list=yes
uid=root
gid=root
auth users=root
secrets file=/etc/rsyncd.secrets

安装inotify

1)、1234 tar-zxvf inotify-tools-3.14.tar.gz
2)、cdinotify-tools-3.14
3)、./configure--prefix=/usr/local/inotify
4)、make;makeinstall

同步脚本:

 

#!/bin/bash
SRC=/databakup/exam
SRC2=/databkup/dspbak
#SRC=/test/test1
#SRC2=/test/test2
HOST=172.16.16.160
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $SRC | while read files
do
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets $SRC root@$HOST::backup
done
~

备份一个文件只能写一条语句

 

[root@web ~]# chmod u+x /root/shell/rsync.sh

[root@web ~]# setsid /root/shell/rsync.sh &

#后台运行脚本,关闭shell终端继续后台运行

rsync.sh脚本加入开机启动项

# echo "/root/shell/rsync.sh" >> /etc/rc.local

防火墙开启rsync端口:873

添加:

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -jACCEPT

防火墙这关要慎重,有些服务器是不允许打开的

重启:

# /etc/init.d/iptables restart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值