rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步
sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或者某一个目录的名字,然后使用rsync同步的时候,只同步发生变化的文件或者目录
实验环境
centos6.5_x64
192.168.10.18 rsync+sersync rsync1
192.168.10.15 rsync rsync2
实验软件
sersync2.5.4_64bit_binary_stable_final.tar.gz
软件安装
cp -pv /etc/hosts /etc/hosts.bak
echo 192.168.10.18 rsync1 >> /etc/hosts
echo 192.168.10.15 rsync2 >> /etc/hosts
sed -i.bak 's/centos6/rsync1/g' /etc/sysconfig/network
rsync -avz /etc/hosts root@192.168.10.15:/etc/hosts
rsync -avz /etc/sysconfig/network root@192.168.10.15:/etc/sysconfig/network rsync1操作
sed -i.bak 's/rsync1/rsync2/g' /etc/sysconfig/network rsync2操作
yum install -y rsync xinetd rsync1/rsync2操作
service xinetd restart && chkconfig --level 35 xinetd on
mkdir -pv /data/back && touch /data/back/{aa.txt,bb.txt}
touch /etc/rsync.passwd && echo 123 > /etc/rsync.passwd
chmod 600 /etc/rsync.passwd rsync1操作
mkdir -pv /data/webback && touch /var/log/rsyncd.log
touch /etc/rsync.passwd && echo back:123 > /etc/rsync.passwd
chmod 600 /etc/rsync.passwd rsync2操作
touch /etc/rsync.conf rsync2操作
cat /etc/rsync.conf
uid = root
gid = root
address =192.168.10.15
port =873
hosts allow =192.168.10.0/24
use chroot = yes
max connections = 40
pid file =/var/run/rsyncd.pid
lock file =/var/run/rsync.lock
log file =/var/log/rsyncd.log
[web]
path = /data/webback/
read only = no
auth users = back
secrets file =/etc/rsync.passwd 可自定义多个模块
rsync --daemon --config=/etc/rsyncd.conf rsync2操作启动服务
rsync -avz /data/back/ back@192.168.10.15::web --password-file=/etc/rsync.passwd rsync1操作
sending incremental file list
./
aa.txt
bb.txt
ll /data/webback/ rsync2操作
total 0
-rw-r--r-- 1 root root 0 Jul 5 15:33 aa.txt
-rw-r--r-- 1 root root 0 Jul 5 15:33 bb.txt
tar zxvf /root/sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
mv /usr/local/GNU-Linux-x86 /usr/local/sersync
ln -s /usr/local/sersync/sersync2 /bin/
cp -pv /usr/local/sersync/confxml.xml /usr/local/sersync/confxml.xml.bak rsync1操作
cat /usr/local/sersync/confxml.xml
<sersync>
<localpath watch="/data/back/"> 监听rsync1源目录
<remote ip="192.168.10.15" name="web"/> rsync2ip 模块名
<auth start="true" users="back" passwordfile="/etc/rsync.passwd"/> 备份用户 密码文件
sersync2 -d -r -o /usr/local/sersync/confxml.xml
option: -o config xml name: /usr/local/sersync/confxml.xml
user isback
passwordfile is /etc/rsync.passwd
execute command: cd /data/back && rsync -artuz -R --delete ./ back@192.168.10.15::web --password-file=/etc/rsync.passwd >/dev/null 2>&1
run the sersync:
watch path is: /data/back
touch /data/back/cc.txt rsync1操作
ll /data/webback/ rsync2操作
-rw-r--r-- 1 root root 0 Jul 5 15:33 aa.txt
-rw-r--r-- 1 root root 0 Jul 5 15:33 bb.txt
-rw-r--r-- 1 root root 0 Jul 5 16:01 cc.txt
cp -pv /etc/rc.d/rc.local /etc/rc.d/rc.local.bak
echo sersync2 -d -r -o /usr/local/sersync/confxml.xml >> /etc/rc.d/rc.local 设置开机启动rsync1操作
cp -pv /etc/rc.d/rc.local /etc/rc.d/rc.local.bak
echo rsync --daemon --config=/etc/rsyncd.conf >> /etc/rc.d/rc.local 设置开机启动rsync2操作
配置多个confxml.xml文件 www bbs blog
sersync2 -d -o /usr/local/sersync/blog_confxml.xml
sersync2 -d -o /usr/local/sersync/bbs_confxml.xml
lsof -i:873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 1462 root 4u IPv4 10842 0t0 TCP rsync2:rsync (LISTEN)