简体   繁体   中英

rsync exclude/include odd behaviour

We have tomcat server located at /opt/tomcat7.0 i want to sync only logs directory to remote server, I am trying following rsync command with exclude * everything and include logs but it doesn't syncing anything.

following are tomcat directories (I only want to sync logs directory)

[rsync@server1]$ ls /opt/tomcat7.0
bin/  conf/  lib/  logs/  temp/  webapps/  work/

here is rsync command

[rsync@logserver]$ rsync -avz --delete --copy-links --include='logs' --exclude='*' server1:/opt/tomcat7.0 /path/to/destination/.
receiving incremental file list

sent 25 bytes  received 10 bytes  6.36 bytes/sec
total size is 0  speedup is 0.00

what am i doing wrong?

任何不这样做的理由:

rsync -avz --delete --copy-links server1:/opt/tomcat7.0/logs /path/to/destination/.

The manpage explains why this does not work and what can be done to make it work:

   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
          - *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM