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 呢?

阅读 14.4k
2 个回答
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.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进