rsync include / exclude

2004-05-06 Thread Michael C. Davis
Hi, I'm using rsync to move the contents of one drive to another as part of
upgrading from an old Linux installation to a newer one.  I have a script
which uses includes and excludes to select what to keep and what to throw
away, but for some reason my include rule isn't triggering when I think it
should.  

I've narrowed it down to a test script for a representative case which,
again, should be working but isn't.  The test script is trying to say
include anything in /usr/etc and its subdirectories from the source tree,
and exclude everything else.  For some reason, this isn't working.
Obviously, I've misunderstood some aspect of how rsync works.  Does anyone
see the problem?  TIA.

script:
---

#!/bin/bash
SRC=/home/mcdavis/mtmaxtor/
DEST=/home/mcdavis/frommaxtor/

# Here is a set of attempts to include, none of which work.
rsync -aHvn --compare-dest=/ --include=/usr/etc/* --exclude=* $SRC
$DEST
rsync -aHvn --compare-dest=/ --include=/usr/etc/ --exclude=* $SRC
$DEST
rsync -aHvn --compare-dest=/ --include=/usr/etc --exclude=* $SRC $DEST
rsync -aHvn --compare-dest=/ --include=/usr/etc/** --exclude=* $SRC
$DEST
rsync -aHvn --compare-dest=/ --include=/usr/etc* --exclude=* $SRC
$DEST
rsync -aHvn --compare-dest=/ --include=usr/etc/* --exclude=* $SRC
$DEST
rsync -aHvn --compare-dest=/ --include=usr/etc/ --exclude=* $SRC $DEST
rsync -aHvn --compare-dest=/ --include=usr/etc --exclude=* $SRC $DEST
rsync -aHvn --compare-dest=/ --include=usr/etc/** --exclude=* $SRC
$DEST
rsync -aHvn --compare-dest=/ --include=usr/etc* --exclude=* $SRC $DEST

# End of script.

Here's what's in the dest prior to running the script

 ls -l /home/mcdavis/frommaxtor
total 0

Here's what's in the src prior to runnning the scripts/

 ls -l /home/mcdavis/mtmaxtor/usr/etc
total 4
-rw-r--r--1 root root 3956 Mar  8  2001 wgetrc

Here's what I get when I run the script, logged in as root:

 ./includetest.sh
building file list ... done
Wrote 40 bytes  Read 16 bytes  112.0 bytes per second
Total size is 0  speedup is 0.00
[ repeat nine more times ]




-- 
To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html


Re: rsync include / exclude

2004-05-06 Thread Michael C. Davis
At 04:50 PM 5/6/04 -0700, Wayne Davison wrote:
You fell victim to one of the classic blunders!  The most famous of
which is, Never get involved in a land war in Asia.  But only slightly
less well known is this: Never exclude '*', when death is on the line!
Ha ha ha ha ha!  Ha ha ha ha!  [Clunk!]

Inconceivable!  OK, guilty as charged.  I started looking at rsync two days
ago.


Here's a serious answer:

Always include ALL the parent dirs when excluding '*'.  Also, consider
using a less powerful trailing exclusion.  In the following example,
I've put the include and exclude rules into a single file named excl:

% cat excl
+ /usr/
- /*
+ /usr/etc/
- /usr/*

% rsync -aHvn ... --exclude-from=excl $SRC $DEST

Or:

% cat excl
+ /usr/
+ /usr/etc/
+ /usr/etc/**
- *

Note that the last two includes in the latter example are both
necessary, as the last one only includes what's inside the
directory, but not the directory itself.


Yes, I see I should have been more careful of the Rules of Unusual
Significance (R.O.U.S.'s).  Your explanation and the man page on the Samba
site make it clear that if a parent directory is excluded, then all of its
descendents are also excluded.  The man page I'd been looking at pertained
to an older rsync version and was less explicit about how include/exclude
works.  (That rule you keep using ... I don'ta think it means what you
think it means.)

Anybody want a peanut?
-- 
To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html