首页 > rsync 同步如何排除一个目录?

rsync 同步如何排除一个目录?

目录接口
/ opt
| -- build
| | -- bin
| | -- res
| | -- image
| -- bin
| -- conf

我想/opt 下面所有文件(排除 /opt/bin 这个目录) 上传到远程服务器

rsync -avzP --progress --delete -r --exclude='bin/' /opt/ 192.168.0.100:/opt

这样build 文件夹下的bin 目录也会排除掉,如何只排除/opt/bin 呢?


rsync -avzP --progress --delete -r --exclude='/bin/' --exclude='./uploads/' /opt/ 192.168.0.100:/opt

if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus "/foo" would match a name of "foo" at either the "root of the transfer" (for a global rule) or in the merge-file’s directory (for a per-directory rule). An unquali‐fied "foo" would match a name of "foo" anywhere in the tree because the algorithm is applied recursively from the top down; it behaves as if each path component gets a turn at being the end of the filename. Even the unanchored "sub/foo" would match at any point in the hierarchy where a "foo" was found within a directory named "sub". See the section on ANCHORING INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a pattern that matches at the root of the transfer.


--exclude='./bin/'啊,建议单独写一个exclude.list,把需要排除的文件和目录写在里面,一行一条,可以使用通配符,也可以写具体匹配的路径。

rsync -avzP --delete --exclude-from=exclude.list

【热门文章】
【热门文章】