Reputation: 9876
I have this following content in a file named "/rsync/include.txt"
+ /home/**
+ /opt**
- *
I then call the rsync
command as follows:
rsync -avr --include-from="/rsync/include.txt" . ../backup
This produces the following output:
sending incremental file list
created directory ../archive
./
opt/
opt/some-file
opt/include-me/
opt/include-me/me-too
opt/include-me/and-me/
sent 299 bytes received 106 bytes 810.00 bytes/sec
total size is 0 speedup is 0.00
The /home
directory exists, and contains files.
Why does the + /home/**
pattern not work? I do not want to use the + /home**
pattern, as that could match other folder names, e.g., /homeopathy
.
Can anybody help me understand why this command doesn't work, and point me in the direction of the working command?
EDIT: While I'd still like an answer to this question, I sincerely suggest using rdiff-backup
as it uses similar filtering files and patterns, but is substantially easier to use. I've spent a good deal of time today on this issue with rsync
, which was resolved in a few minutes using rdiff-backup
.
Upvotes: 1
Views: 387
Reputation: 4589
The easiest way to see if your filter rules do what you want, is to use -vv
(increase verbosity twice) in combination with -n
(dry-run).
With double verbosity you will see which pattern caused which file to be ignored.
You may grep
the output to only see the relevant parts.
Example
% rsync -avv --include 'opt/1' --exclude 'opt/*' -n ./ /tmp \
| grep '\[sender\]'
[sender] showing directory opt/1 because of pattern opt/1
[sender] hiding directory opt/2 because of pattern opt/*
[sender] hiding directory opt/3 because of pattern opt/*
Your example fails because + /home/**
is excluded by - *
.
man rsync states:
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.
So the pattern /home/**
will be evaluated after /home
is traversed, but this will never happen, because - *
excludes /home
.
To include /home/
you just have to insert it before /home/**
, so your exclude file becomes:
+ /home/
+ /home/**
+ /opt/
+ /opt/**
- *
Upvotes: 1