Filter file: selected directories only

rsync at xbit.ru rsync at xbit.ru
Wed Oct 7 17:17:09 MDT 2009


Thank you, it works.

But if I want to delete only certain files or dirs from remote side?

example:

$ tree dirA/
dirA/
|-- dir2
|   `-- file3
|-- file1
`-- file2

$ tree dirB/
dirB/
|-- dir2
|   `-- file3
|-- file1
|-- file2
`-- protect1

$ rsync -av --dry-run --delete-excluded -f ". filter" dirA/ dirB/
building file list ... done
./

sent 74 bytes  received 26 bytes  200.00 bytes/sec
total size is 0  speedup is 0.00

$ cat filter
H *
P *
R dir2*
- dir2*

I want to delete "dirB/dir2/" only. Not "dirB/protect1" or any other
file or dir in "dirB/".
What sort of filter I must create?
Where can I find example filter files for complicated cases?


> On Sun, 2009-10-04 at 00:29 +0400, rsync at xbit.ru wrote:
>> I'm trying to create a filter file for rsync what saying which dirs to
>> copy. For example  i need only /lib and /var/lib dirs from remote
>> server.
>> I say:
>>  rsync -f ". /tmp/rsync_dirs"  --dry-run --verbose "remote:/"
>> "/local_dir/".
>>
>> File /tmp/rsync_dirs looks like:
>> + /lib/
>> + /var/
>> -! /var/lib/*
>> - /*
>>
>> This doesnt work: it copies all /var/ dir except contents of /var/lib/.
>> What's wrong?
>
> Your third rule excludes all files that don't match "/var/lib/*",
> and /var/lib is such a file since it has no third path component to
> match the "*".  Hence the behavior you're seeing.
>
> Instead, try this approach of including the /var/lib dir and then
> excluding everything else at the /var/* level:
>
> + /lib/
> + /var/
> - /*
> + /var/lib/
> - /var/*
>
> In practice, I have never found a legitimate use for "!" patterns and
> believe they are a misfeature.  From the version-control history, it
> appears that the only use Wayne had in mind for them was to replace the
> traditional --include='*/' --exclude='*' (or --filter='S */'
> --filter='H *') pattern, but I really don't see what was wrong with that
> pattern, as it is consistent with the spirit of all other filter usage I
> have seen.  Wayne, comments?
>
> --
> Matt
>
>
>




More information about the rsync mailing list