rsync+inotify 配置实时同步服务器

1.安装inofity-tools工具及rsync在服务器上(注意是服务器,即被备份的系统上),安装rsync在客户端上(即备份系统上,存储服务器的备份文件)

2.在客户端上配置:/etc/rsyncd.conf文件,内容如下:

uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[yang11]
#这个目录一定要存在
path = /home/linux/save
comment = linux home data
ignore errors
read only = no
write only = no
hosts allow = *
hosts deny = 172.16.16.11
list = false
uid = root
gid = root
auth users = backup
secrets file = /etc/server.pass

再在客户端建立:/etc/server.pass文件,且权限为:600,内容如下:

backup:yang123


然后在客户端启动:rsync --daemon


3.在被备份的系统上写个脚本(即安装了inofity-tools工具及rsync工具的系统上),假设名为:rsync_inotify.sh,内容如下:

#! /bin/bash
host1=172.16.16.202

src=/home/linux/LinuxTools

user="backup"
modelName="yang11"

/usr/bin/inotifywait -mrq --timefmt '%y/%m/%d %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/rsync.pass $src $user@$host1::$modelName
		echo "$files was rsynced" >> /tmp/rsync.log 2>&1
	done

4.然后运行这个脚本就可以了。


你可能感兴趣的:(Linux学习,Linux运维)