Bug 2647 - --exclude options work from commandline but not in script
Summary: --exclude options work from commandline but not in script
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 2.6.4
Hardware: x86 Linux
: P3 major (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
Depends on:
Reported: 2005-04-25 13:46 UTC by Jason
Modified: 2005-06-03 01:39 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Jason 2005-04-25 13:46:04 UTC
Greetings!  Thank you for such a wonderful tool in rsync.

I am trying to use rsync to back up one filesystem tree to another on the same
disk.  The catch is that the destination tree is mounted under the source tree.
 To prevent the backup from getting a copy of itself, I have tried to use the
--exclude option, but to no avail.  The general procedure for my script is to cd
to the destinateion directory (in this case: /mnt/backup) and rsync the source
directory (in this case: /) to the destination directory.  Here's the command
that gets run:

/usr/bin/rsync -v --progress --delete --stats --exclude='/proc/'
--exclude='/sys/' --exclude='/mnt/sysbackup/' -aS / .

I want to exclude the /sys, /proc, and /mnt/sysbackup directories and
*everything* underneath them from being backed up to the /mnt/sysbackup
directory.  The kicker is that if I run that command manually like so:

( cd /mnt/sysbackup; /usr/bin/rsync -v --progress --delete --stats
--exclude='/proc/' --exclude='/sys/' --exclude='/mnt/sysbackup/' -aS / . )

it works fine.  When the exact same rsync command is run from within the script
(following the cd /mnt/sysbackup command), I get a /mnt/sysbackup/mnt/sysbackup
directory with *everything* under the /mnt/sysbackup directory duplicated.  I
also get /mnt/sysbackup/sys and /mnt/sysbackup/proc directories complete with
data in them.

Comment 1 John Van Essen 2005-04-25 18:50:20 UTC
A possible explanation is if the single-quotes are being retained in the
--exclude values instead of being removed by whatever shell you are using for

So rsync tries to exclude   '/proc/'  instead of  /proc/

In your case, the quotes aren't even needed since you don't have wildcards,
shell metachars, or whitespace in those path values.

Remove the single-quotes and see if that helps.  If it does, then either your
shell has a problem or they weren't really single-quotes to begin with.
Comment 2 Jason 2005-04-26 06:27:24 UTC
That is an interesting suggestion and one I dismissed out of hand.  However, it
is possible and I will evaluate that possibility.  Thank you.  I have removed
the single quotes from surrounding the exclude values and testing that.

FYI, here is the shell that I am using:

# bash --version
GNU bash, version 2.05b.0(1)-release (i686-pc-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.
Comment 3 Jason 2005-04-26 12:55:23 UTC
Hrm.  Well, that suggestion didn't appear to work.  The command that was run now

/usr/bin/rsync -v --progress --delete --stats --exclude=/proc/ --exclude=/sys/
--exclude=/mnt/sysbackup/ -aS / .

It still synced the directories that it shouldn't.  I am going to strace it and
see if I can figure out what is going on...
Comment 4 Wayne Davison 2005-04-27 01:55:21 UTC
Rsync doesn't care about being run from inside a script or not.  Depending on
how the script was run, there can be differences in environment variables, but
nothing in the command you mentioned should be affected by that (AFAICS).

You should be looking for something in the script that is not quite what you
think it is -- some subtle difference between the command you ran manually and
the actual command in the script (such as a different source dir, a misspelled
exclude, etc.).  If you can't find what's wrong, feel free to attach the script
to this bug report.
Comment 5 Dmitri Zoubkov (dead mail address) 2005-05-16 23:31:08 UTC
This isn't rsync issue but a strange manner how bash escapes the <'>.
### Script 1 (won't work):
rsync -avuz "$EXLUDES" /source /destination
### Script 2 (won't either):
RSYNC="rsync -avuz --exclude='/whatever/' /source /destination"
### Script 3 (works as expected):
rsync -avuz "$EXLUDES" /source /destination
Comment 6 Wayne Davison 2005-05-17 00:11:31 UTC
> ### Script 3 (works as expected)

If by "works as expected" you mean that it excludes a file whose name is a
single apostrophe whose grandparent directory also has a name of a single
apostrophe.  (That's certainly what I expect it to do, and what it actually does
too.)  Maybe you meant to write this VAL assignment?


Keep in mind that shell-special characters are not re-parsed when expanding
variables (which would be very bad) unless you use eval.  It may also help to
note that writing --exclude='foo' is exactly the same as writing '--exclude=foo'
(it's just that the former seems more natural to most people), so there's no
need for all the extra quotes in what you're trying to do -- just quote the
values when assigning them to a variable and they'll be fine.