6

[I had to change the example to make it clear that there are subdirectories.]

Let's say I want to recreate a subset of my hierarchy. for arguments sake, let's say I want to backup files in filelist.conf

# cat rsync-list
ab*
bb*

and

# find .
.
./abc
./abc/file-in-abc
./abd
./abd/file-in-abd
./aca
./bba
./bbc
./bca
./rsync-list

I would have hoped that

rsync -arv --include-from=rsync-list --exclude='*' . /somewhere-else

would recreate abc, abd, bba, and bbc. the problem is that it does not descend into the ab* directories, so it does not do abc/file-in-abc and abd/file-in-abd. so, in this sense, the ab* is not really a wildcard that is expanded into abc and abd and then rsynced.

  • * doesn't match / in shell wildcard expansion either. Use ** instead. – muru Jan 4 '15 at 21:08
  • 1
    two more hints: [1] -vv will explain why patterns make it or not. [2] to include a subdirectory, its paths need to be included. e.g., if /etc/logrotate.d/ is in the list, it will be ignored unless /etc is also in the list . – ivo Welch Jan 12 '15 at 18:14
14

The manpage lists these five options:

--exclude=PATTERN       exclude files matching PATTERN
--exclude-from=FILE     read exclude patterns from FILE
--include=PATTERN       don't exclude files matching PATTERN
--include-from=FILE     read include patterns from FILE
--files-from=FILE       read list of source-file names from FILE

--files-from is for exact filenames, and --include-from is for patterns, so you might want to try that instead.

Using include-from, you don't need to specify +, but you do need to exclude everything else. For example, given:

$ ls -v1 source
image1.tiff
...
image700.tiff
$ cat includes
image7*.tiff

Then I can sync only image7*.tiff using:

rsync -aP --include-from=includes --exclude='*' source/ target

The manpage also says, in the INCLUDE/EXCLUDE PATTERN RULES section:

  • a ’*’ matches any path component, but it stops at slashes.
  • use ’**’ to match anything, including slashes.
4

You can use --include-from instead of --files-from if you want to use wildcards. filelist.conf should look like this:

+ /usr/lib/ld-* 
+ /usr/bin/gcc*
+ /etc/passwd
+ /etc/nonexisting
- *

You need to specify + or - to include or exclude in the file. The - * rule at the end is necessary to make include rules work since everything is included by default. Don't put this first or it overrides the include rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.