我们有位于/opt/tomcat7.0
的tomcat服务器我想只将logs
目录同步到远程服务器,我正在尝试关注rsync
命令并排除*
所有内容并包含{ {1}}但它不会同步任何内容。
以下是tomcat目录(我只想同步logs
目录)
logs
这里是rsync命令
[rsync@server1]$ ls /opt/tomcat7.0
bin/ conf/ lib/ logs/ temp/ webapps/ work/
我做错了什么?
答案 0 :(得分:1)
任何不做的理由:
rsync -avz --delete --copy-links server1:/opt/tomcat7.0/logs /path/to/destination/.
答案 1 :(得分:0)
该联机帮助页解释了为什么这不起作用以及如何使其工作:
Note that, when using the --recursive (-r) option (which is implied by -a), every subcomponent of every path
is visited from the top down, so include/exclude patterns get applied recursively to each subcomponent's full
name (e.g. to include "/foo/bar/baz" the subcomponents "/foo" and "/foo/bar" must not be excluded). The
exclude patterns actually short-circuit the directory traversal stage when rsync finds the files to send. If
a pattern excludes a particular parent directory, it can render a deeper include pattern ineffectual because
rsync did not descend through that excluded section of the hierarchy. This is particularly important when
using a trailing '*' rule. For instance, this won't work:
+ /some/path/this-file-will-not-be-found
+ /file-is-included
- *
This fails because the parent directory "some" is excluded by the '*' rule, so rsync never visits any of the
files in the "some" or "some/path" directories. One solution is to ask for all directories in the hierarchy
to be included by using a single rule: "+ */" (put it somewhere before the "- *" rule), and perhaps use the
--prune-empty-dirs option. Another solution is to add specific include rules for all the parent dirs that
need to be visited. For instance, this set of rules works fine:
+ /some/
+ /some/path/
+ /some/path/this-file-is-found
+ /file-also-included
- *