Search code examples
bashsshrsync

Rsync only two dictionaries


I want to work localy on some programm, which I want to test and run on a remote server. The only files I am editing are the *.hpp and *.cpp in the src and the include directory.

For that I tried this rsync command, to only upload the necessarry source files:

rsync --dry-run -av --exclude '*' --include 'src/*.cpp' --include 'include/*.hpp' Programm/ user@remote:/home/user/Programm

But for some reason no files are commited to the server after some local changes.

Any hints appreciated!

Thank you


Solution

  • Here's excerpt from the rsync man page, which tackles your exact problem.

    Note that, when using the --recursive (-r) option (which is implied by -a), every subdir component of every path is visited left to right, with each directory having a chance for exclusion before its content. In this way include/exclude patterns are applied recursively to the pathname of each node in the filesystem's tree (those inside the transfer). The exclude patterns short-circuit the directory traversal stage as rsync finds the files to send.

    For instance, to include "/foo/bar/baz", the directories "/foo" and "/foo/bar" must not be excluded. Excluding one of those parent directories prevents the examination of its content, cutting off rsync's recursion into those paths and rendering the include for "/foo/bar/baz" ineffectual (since rsync can't match something it never sees in the cut-off section of the directory hierarchy).

    The concept path exclusion 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
    - *