参数
-n 测试传输状态 是否成功 dry-run
-a 归档 相当于 ugtopD等
-v 显示同步过程
-z 压缩
-t time时间信息
-g gourpID 属组ID
-o owner 属主ID
-e 指定协议或通道 ssh -p 22
-p 保持原来的权限
-D devices设备文件
--delete 无差异进行同步
--exclude 排除 多个可以使用 --exclude={a,b,c,d}
--exclude-form 排除多个文件 可以使用 --exclude-from=file.txt
--progress 显示备份过程
--config=file 指定rsyncd.conf的配置路径
rsync讲解
#Global Settings
uid = nobody
gid = nobody
use chroot = no(是否禁锢用户家目录)
max connections = 10(最大连接数)
strict modes = yes(是否完全检查)
pid file = /var/run/rsyncd.pid 运行进程ID
log file = /var/log/rsyncd.log 运行日志
lock file=/var/run/rsync.lock 锁文件
#Directory to be synced
[data]
path = /data 路径
ignore errors = yes(是否忽略错误)
read only = no(只读)
write only = no(只写)
hosts allow = white_list_ip/net 白名单
hosts deny = black_list_ip/net 黑名单
list = false 是否允许列出名单
auth users = username (允许的用户)
secrets file = /etc/rsync.passwd 用户密码的存放位置
#Global Settings uid = nobody gid = nobody use chroot = no max connections = 10 strict modes = yes pid file = /var/run/rsyncd.pid log file = /var/log/rsyncd.log lock file=/var/run/rsync.lock #Directory to be synced [data] path = /data ignore errors = yes read only = no write only = no hosts allow = 172.16.0.0/24 hosts deny = 0.0.0.0/32 list = false auth users = user100 secrets file = /etc/rsync.passwd
rsync --daemon 模式
rsync -avz ./index.php user100@172.16.30.100::data --password-file=/etc/rsync.passwd
rsync ssh通道模式
rsync -avz -e "ssh -p 22" ./index.php user100@172.16.30.100:/data
host=172.16.30.100
src=/data
dst=data
user=user100
pwd=/etc/rsync.passwd
cmd=/usr/local/inotify-tools-3.14/bin
#
#cd /usr/local/inotify-tools-3.14/bin
${cmd}/inotifywait -mrq --format '%f' -e create,close_write,delete $src \
| while read line
do
cd $src
rsync -aruz -R --delete ./ ${user}@${host}::${dst} --password-file=/etc/rsync.passwd >/dev/null 2>&1
done
Inotify讲解