# rsync --exclude-from=<file> problem

## Moriah

I am having a problem with rsync.  This is actually a gentoo/cygwin problem, so please bear with me.  I am rsync-ing from a windoze box using rsync under cygwin to a gentoo box.  I can't seem to get the --exclude-from option to work for me.  I suspect it has to do with the fact that I am rsyncing the whole windoze box, starting with /cygdrive/c/, and STUPID windoze has spaces in some of the directory names above the stuff I want to exclude.  I suspect that these spaces are confusing the parser in rsync, so it doesn't match my exclude file up properly with the right files.    :Evil or Very Mad: 

Here is what my exclude list looks like:

```
# the exclude list starts here:

/cygdrive/c/Documents and Settings/rj/My Documents/My Virtual Machines/

# the exclude list ends here
```

And here is what my invocation of rsync looks like:

```
# log into the client then run rsync to send files to the server

ssh "${REMOTE_USER}"@${IP} \

    "rsync -v --delete -a --stats \

     --exclude-from=backup_exclude_list --delete-excluded \

         /cygdrive/${DRIVE_LETTER} \

         root@${BU_SERVER}:/bu/backups/${MACHINE}/cygdrive"
```

Any ideas why the --exclude-from isn't working.   :Question: 

----------

## ppurka

You can probably take care of the spaces by escaping them with '\'. Like file\ with\ space.txt. My exclude file looks similar to this (note the + and - and ***):

```
# exclude-file:

- **/.adobe/***

- **/amarok/albumcovers/***

- **/*[Cc]ache*/**

- **/.picasa/***

- **/thumbnails/**

- **/.thumbnails/***

+ /home/<user>/*

+ /home/<user>/.*
```

----------

## Moriah

Nope.  Tried that.  Didn't work.  Ditto for quoting each full filename.  Still didn't work.  I think rsync doesn't know how to parse pathnames with spaces in them.    :Crying or Very sad: 

I really do not understand your exclude file at all.  What is with the + and - chars, and why more than 1 star in any given position?

Plus, I do not see any back-slashes anywhere in your exclude file.    :Sad: 

----------

## ppurka

 *Moriah wrote:*   

> Nope.  Tried that.  Didn't work.  Ditto for quoting each full filename.  Still didn't work.  I think rsync doesn't know how to parse pathnames with spaces in them.   

 Hmm.. can't help you then. I am quite surprised actually.

 *Quote:*   

> I really do not understand your exclude file at all.  What is with the + and - chars, and why more than 1 star in any given position?

 You will have to read the man page for that, and especially for the meaning of *, ** and ***.  :Wink: 

- means the file or directory or path is excluded. The *, ** and *** defines what is excluded and what is not.

+ means included.

 *Quote:*   

> Plus, I do not see any back-slashes anywhere in your exclude file.   

 That's because none of my paths have any spaces in them.   :Rolling Eyes: 

----------

## Moriah

I am also quite suprised.  There's gotta be a way.  I can't be the only person who has ever tried this.

----------

## Bones McCracker

I think the reason escaping the spaces didn't work is because you are specifying the exclude pattern in a shell command (as opposed to an exclude file), so the spaces are only being escaped for the shell in which the command is being executed (on your computer), and not in the shell running rsync (on the remote system).  So you could try single-quoting the portion of the command which you currently have double-quoted, or single quoting portions of it.  Or, you could try using an exclude file like ppurka suggested.

Alternatively, you could try using pattern-matching (with a ? replacing the space).  Search the rsync man page for INCLUDE/EXCLUDE PATTERN RULES (which will also answer your questions about the use of multiple * symbols and leading + and - characters).  It takes some mental digestion to get used to this somewhat unusual, although efficient, syntax.

----------

## Moriah

Look closely -- it *IS* a separate exclude file: 

```
--exclude-from=backup_exclude_list 
```

----------

## Bones McCracker

 *Moriah wrote:*   

> Look closely -- it *IS* a separate exclude file: 
> 
> ```
> --exclude-from=backup_exclude_list 
> ```
> ...

 

Sorry.  Well, I guess that's not it then.   :Laughing: 

The only other thing that occurs to me is using the ? in a match, to match the space, as noted above.

I personally haven't run into this before.

----------

## Moriah

WOW!  Why didn't I think of that?  That sounds hopeful.  I'll try using the "?" where the space goes and see what happens.  Since this is my nightly backup server, the answer will have to wait until tomorow morning.  I'll post the results.

----------

## Bones McCracker

 *Moriah wrote:*   

> WOW!  Why didn't I think of that?  That sounds hopeful.  I'll try using the "?" where the space goes and see what happens.  Since this is my nightly backup server, the answer will have to wait until tomorow morning.  I'll post the results.

 

Make sure you check the man page section I indicated earlier in reference to this, so you get the format right (e.g., I'm not sure if you have to escape the ? or something).

----------

## Moriah

Well, even using the "?" in place of the space, rsync still backed up the excluded path.    :Evil or Very Mad: 

It just doesn't work, and I cannot figure out why.  I've never had any trouble excluding parts of the tree when a Linux box was being backed up.  Why should an windoze XP box running rsync under cygwin work any differently?

----------

## Bones McCracker

 *Moriah wrote:*   

> Well, even using the "?" in place of the space, rsync still backed up the excluded path.   
> 
> It just doesn't work, and I cannot figure out why.  I've never had any trouble excluding parts of the tree when a Linux box was being backed up.  Why should an windoze XP box running rsync under cygwin work any differently?

 

Start isolating the problem.

Run rsync locally on the machine, from within cygwin, and see if you can get it to work.  Try something simple that tests your cases of excluding files with and without spaces in the filenames.

Give some thought to whether text encodings or other differences in how filenames are handled might have something to do with it.

----------

## Moriah

Good thought on the excodings.  I had much grief recently trying to set up a windoze memory mapped file as a shared memory region for an unmanaged C++ program to communicate with a C# program on the same machine.  The problem turned out to be the default encoding chosen gratuitously by the Visual Stupidio IDE is different from C++ and C#.  DUH!    :Evil or Very Mad: 

Maybe that is it.  I'll look into it.  Thanks for the idea.    :Very Happy: 

----------

