

[[email protected] ~]# ls /abc
fstab group passwd
[[email protected] ~]# ls /test/
[[email protected] ~]# rsync -avz /abc /test #同步没有加/,整个文件夹同步
[[email protected] ~]# ls /test/
abc
[[email protected] ~]# rsync -avz /abc/ /test #加/只同步文件内容
[[email protected] ~]# ls /test/
abc fstab group passwd
[[email protected] ~]# echo 123 >> /abc/group #写入内容
[[email protected] ~]# rsync -acz /abc/ /test/ #同步变化的数据
[[email protected] ~]# touch /test/ahha.txt #创建一个文件
[[email protected] ~]# ls /test/
ahha.txt fstab group passwd
[[email protected] ~]# rsync -acz --delete /abc/ /test/ #同步 ,多余删除
[[email protected] ~]# ls /test/
fstab group passwd
[[email protected] ~]# rsync -avz --delete /abc/ [email protected]192.168.4.100:/opt/ #同步到
[email protected]192.168.4.100's password:

- 案例五:实时同步
- A主机安装notify-tools工具服务


[[email protected] ~]# rpm -ivh inotify-tools-3.14-8.el7.x86_64.rpm
警告:inotify-tools-3.14-8.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, ** ID 352c64e5: NOKEY
准备中... ################################# [100%]
软件包 inotify-tools-3.14-8.el7.x86_64 已经安装
[[email protected] ~]# inotifywait #运行命令
No files specified to watch! #没有监控文件
[[email protected] init.d]# vim rsync.sh #创建脚本
#! /bin/bash
while inotifywait -rqq /abc #
do
rsync -az --delete /abc/ [email protected]192.168.4.200:/opt/ #监控A主机/abc/文件 同步到主机 /opt/
done
[[email protected] init.d]# /etc/init.d/rsync.sh & #后台运行脚本
[1] 8857