How to mirror only specified directories

Paul Slootman paul+rsync at wurtel.net
Tue Sep 28 09:38:15 MDT 2010


On Tue 28 Sep 2010, Ian Skinner wrote:

> I am trying to mirror only select directories from one server to another with rsync through its daemon mode.
> 
> Server A
> /export
>    /home
>       /A-do
>       /A-not
>       /A-copy
>       /das
>          /htdocs
>             /docs
>       /em
>          /htdocs
>             /docs
>       /psb
>          /htdocs
>             /docs
>       /X-do
>       /X-not
>       /X-copy
> 
> Server B
> /export
>    /home
>       /extranet
>          /das
>             /htdocs
>                /docs
>          /em
>             /htdocs
>                /docs
>          /psb
>             /htdocs
>                /docs
> 
> I wish to copy everything in the /docs directories under the /das, /em and /psb directories (in this simplified example) moving them from /export/home on server A to /export/home/extranet on server B.
> 
> This is what I have in a rsyncd.conf on server B.
> [dprweb_extranet]
>    path = /export/home/extranet
>    comment = California Department of Pesticide Regulation Extranet
>    uid = webuser
>    gid = other
>    read only = no
>    list = yes
>    hosts allow = ww.xxx.yy.zz
>    secrets file = /etc/.password
>    auth users = aaa
> 
> Here is the command I've tried on server A
> /usr/local/bin/rsync -n -vvv --stats -Pzrtpl --delete --password-file=/export/home/webuser/.appprod --log-file=/export/home/webuser/logs/rsync-log --include "/export/home/[internal|das|em|enf|itb|medtox|pml|psb|reg|whs]/htdocs/docs/*" --exclude "/*"  /export/home/xterernal/htdocs/ webuser at appprod::dprweb_extranet
> 
> This is failing with this message in the output.
> sending incremental file list
> rsync: change_dir "/export/home/xterernal/htdocs" failed: No such file or directory (2)
> 
> Question A:
> Why was it looking at the "/export/home/xterernal/htdocs" directory.  The external is one of the many directories I am trying to ignore.

You have explicitly told it to use /export/home/xterernal/htdocs/ as the
source directory!
Note that you wrote "xterernal" which is not the same as "external".


> Question B: 
> Where is it trying to change to the /export/home/xterernal/htdocs directory?  On server B?  If so, that is not the desired path, /export/home/extranet/... is the desired destination.

No, on the source, see answer to question B.


> Can anybody provide some guidance on how to filter to select directories and mirror them to another server with a different base path?

You need to know that include/exclude patterns are anchored at the root
of the transfer. It's a bit difficult from your message to see what
exactly you're trying to transfer and exclude, but if you want to
transfer /export/home/external/htdocs/ which contains subdirectories
"yes" and "no", to exclude the "no" directory use this:

rsync -aP --exclude /no /export/home/external/htdocs/ remote::whatever/

Also, using [] in patterns is only supported for character ranges as in
[0-9], not for lists of words.



Paul


More information about the rsync mailing list