赞
踩
注意:exclude可单独使用,include必须和exclude配合使用
服务端:
在做同步之前必须要知道的含义:
不同步目录
- $ rsync -e 'ssh -p 24858' -avz --progress --exclude='*/' --prune-empty-dirs ./ kk@10.0.8.84:/home/kk/test/
- building file list ...
- 4 files to consider
- ./
- a.txt
- 2 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=2/4)
- b.txt
- 2 100% 1.95kB/s 0:00:00 (xfr#2, to-chk=1/4)
- c.txt
- 2 100% 1.95kB/s 0:00:00 (xfr#3, to-chk=0/4)
-
- sent 262 bytes received 76 bytes 676.00 bytes/sec
- total size is 6 speedup is 0.02
仅同步a目录
- $ rsync -e 'ssh -p 24858' -avz --progress --include='*/' 'a' --exclude='*' --prune-empty-dirs ./ kk@10.0.8.84:/home/kk/test/
- building file list ...
- 10 files to consider
- a/
- a/b/
- a/b/c/
-
- sent 235 bytes received 21 bytes 512.00 bytes/sec
- total size is 0 speedup is 0.00
仅同步a目录下的a.txt文件
- $ cd /home/kk/test
- $ rsync -e 'ssh -p 24858' -avz --progress --include='*/' --include='a/a.txt' --exclude='*' --prune-empty-dirs ./ kk@10.0.8.84:/home/kk/test/
- building file list ...
- 8 files to consider
- ./
- a/
- a/a.txt
- 2 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=5/8)
-
- sent 266 bytes received 41 bytes 614.00 bytes/sec
- total size is 2 speedup is 0.01
同步所有的a.txt文件(这是在目标目录没有该文件的情况下,会全部同步,如果某个目录下有了该文件,则不会替换)
- $ rsync -e 'ssh -p 24858' -avz --progress --include='*/' --include='a.txt' --exclude='*' --prune-empty-dirs ./ kk@10.0.8.84:/home/kk/test/
- building file list ...
- 9 files to consider
- ./
- a.txt
- 2 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=7/9)
- a/
- a/a.txt
- 2 100% 1.95kB/s 0:00:00 (xfr#2, to-chk=5/9)
-
- sent 334 bytes received 60 bytes 788.00 bytes/sec
- total size is 4 speedup is 0.01
当然,如果要同步文件过多,还可以结合 --include-from 参数使用,将所有要通的文件路径写入到一个文件中
eg:
- $ cat rsync.txt
- a/a.txt
- b/b.txt
- c/c.txt
-
-
- $ rsync -e 'ssh -p 24858' -avz --progress --include='*/' --include-from='./rsync.txt' --exclude='*' --prune-empty-dirs ./ kk@10.0.8.84:/home/kk/test/
- building file list ...
- 10 files to consider
- ./
- a/
- a/a.txt
- 2 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=7/10)
- b/
- b/b.txt
- 2 100% 1.95kB/s 0:00:00 (xfr#2, to-chk=3/10)
- c/
- c/c.txt
- 2 100% 1.95kB/s 0:00:00 (xfr#3, to-chk=1/10)
-
- sent 429 bytes received 85 bytes 1,028.00 bytes/sec
- total size is 6 speedup is 0.01
-
好了,这就是rsync之include、exclude使用的方法了,如有问题可与博主一起交流讨论!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。