I was under the impression that --include and --exclude worked by matching patterns in the order given, and whichever matched first, whether that was an include or exclude determined the action for that file. I have a big directory from which I am attempting to transfer selected files. I want all files where the first level directory is anything, the second level directory is "2005" and the third level is the file "07.tar.bz2". So I started with these options (different tries on each line): --include '**/2005/07.tar.bz2' --exclude '**' --include '**/2005/07.tar.bz2' --exclude '*' --include '*/2005/07.tar.bz2' --exclude '**' --include '*/2005/07.tar.bz2' --exclude '*' I also tried numerous other random variations. Either I get absolutely no files at all matching, or I get everything in the entire directory tree to match. I hope what I want is clear to you. How can I make it clear to rsync? I've had several other cases of this in the past, and stumbled on something that worked without really understanding why. So I guess the explanations in the man page just didn't really give me the correct understanding of how this works. Maybe someone can try explaining in another way. -- ----------------------------------------------------------------------------- | Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ | | (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ | -----------------------------------------------------------------------------
On Sun, Nov 27, 2005 at 11:10:39AM -0600, Phil Howard wrote:> --include '**/2005/07.tar.bz2' --exclude '**'Taken from the manpage: Note that, when using the --recursive (-r) option (which is implied by -a), every subcomponent of every path is visited from the top down, so include/exclude patterns get applied recursively to each subcomponent's full name (e.g. to include "/foo/bar/baz" the subcomponents "/foo" and "/foo/bar" must not be excluded). The exclude patterns actually short-circuit the directory traversal stage when rsync finds the files to send. If a pattern excludes a particular parent directory, it can render a deeper include pattern ineffectual because rsync did not descend through that excluded section of the hierarchy. This is particularly important when using a trailing '*' rule. So, with your rules, nothing can ever match because all the base-level dirs (and files) are excluded. ..wayne..
On 11/27/05, Phil Howard <phil-rsync-2@ipal.net> wrote:> I was under the impression that --include and --exclude worked by matching > patterns in the order given, and whichever matched first, whether that was > an include or exclude determined the action for that file. I have a big > directory from which I am attempting to transfer selected files. I want > all files where the first level directory is anything, the second level > directory is "2005" and the third level is the file "07.tar.bz2". So I > started with these options (different tries on each line): > > --include '**/2005/07.tar.bz2' --exclude '**' > --include '**/2005/07.tar.bz2' --exclude '*' > --include '*/2005/07.tar.bz2' --exclude '**' > --include '*/2005/07.tar.bz2' --exclude '*' > > I also tried numerous other random variations. Either I get absolutely no > files at all matching, or I get everything in the entire directory tree to > match. > > I hope what I want is clear to you. How can I make it clear to rsync? > > I've had several other cases of this in the past, and stumbled on something > that worked without really understanding why. So I guess the explanations > in the man page just didn't really give me the correct understanding of how > this works. Maybe someone can try explaining in another way. > > -- > ----------------------------------------------------------------------------- > | Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ | > | (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ | > -----------------------------------------------------------------------------I think you are trying to include too many things in a single include/exclude statement. You need to break everything down to files, folders, and sets of files in a single folder. For example, if you want to transfer a file 3 directories deep, each parent directory needs to be included if there is a global exclude at the end of your statements. The following will probably give you what you want: --include "/*" (include all files at root of transfer) --include "/*/2005/" --include "/*/2005/07.tar.bz2" (include file 07.tar.bz2, you must also include the folder that contains the file because of the next statement) --exclude "*" (exclude everything not explicitly included) I haven't tested it, so YMMV. -- Aaron W Morris (decep) <aaronwmorris@gmail.com>