客户端排除打包法
在我们生产环境中,可能会遇到这种情况,当一个目录下面有多个文件的时候,由于其中有一个文件比较大,并且我们也不需要被客户端拉取,那么此时我们就可以使用排除打包来实现,过滤一个或者多个文件。
示例:
1、准备同步的文件
[root@node1 ~]# ls /data/
a b c d e f fstab g rc.local
2、测试排除单个文件
[root@node2 ~]# rsync -avz --exclude=a --password-file=/etc/rsync.passwd caichangen@192.168.1.71::cce test/
receiving incremental file list
./
b
c
d
e
f
fstab
g
rc.local
sent 221 bytes received 1107 bytes 2656.00 bytes/sec
total size is 1025 speedup is 0.77
3、测试排除多个文件
[root@node2 ~]# rsync -avz --exclude={a,b} --password-file=/etc/rsync.passwd caichangen@192.168.1.71::cce test/
receiving incremental file list
./
c
d
e
f
fstab
g
rc.local
sent 209 bytes received 1065 bytes 2548.00 bytes/sec
total size is 1025 speedup is 0.80
4、批量排除
[root@node2 ~]# rsync -avz --exclude={a..f} --password-file=/etc/rsync.passwd caichangen@192.168.1.71::cce test/
receiving incremental file list
./
fstab
g
rc.local
sent 161 bytes received 897 bytes 2116.00 bytes/sec
total size is 1025 speedup is 0.97
5、排除一些不规律的文件
[root@node2 ~]# echo -e "a\nd\ne\nf\ng" > /tmp/paichu.txt
[root@node2 ~]# cat /tmp/paichu.txt
a
d
e
f
g
[root@node2 ~]# rsync -avz --exclude-from=/tmp/paichu.txt --password-file=/etc/rsync.passwd caichangen@192.168.1.71::cce test/
receiving incremental file list
./
b
c
fstab
rc.local
sent 173 bytes received 939 bytes 2224.00 bytes/sec
total size is 1025 speedup is 0.92
服务端排除打包法
1、让客户端来拉取的时候,过滤一些数据,不允许拉取
[root@node1 ~]# tail -1 /etc/rsyncd.conf
exclude=a b #如果是某个目录下那么就可以这样使用 dir/no_sync
[root@node1 ~]# systemctl restart rsyncd
[root@node1 ~]# ls /data/
a b c d e f fstab g rc.local
2、测试是否排除成功
[root@node2 ~]# rsync -avz --password-file=/etc/rsync.passwd caichangen@192.168.1.71::cce test/
receiving incremental file list
./
c
d
e
f
fstab
g
rc.local
sent 195 bytes received 1065 bytes 2520.00 bytes/sec
total size is 1025 speedup is 0.81