Question about include/exclude rules

Wayne Davison wayned at samba.org
Thu Jun 30 19:35:39 GMT 2005


On Tue, Jun 28, 2005 at 02:22:22PM +0200, l.corbo at pronetics.it wrote:
> Rsync works fine for me (the rules are reported below) except a point,
> rsync create an empty folders structure that I don'want.

The only way to get rsync to not create directory hierarchies that don't
contain *.txt files is to actually remove the directories from the
transfer, either through more targeted directory includes, or by using
--files-from (though the latter would not make it easy to delete missing
files).

So, instead of the "+ */" rule you would need to maintain some include
rules, perhaps using something like this perl script:

    #!/usr/bin/perl
    use strict;
    my $dir = shift;
    chdir($dir) or die "Unable to chdir to $dir: $!\n";
    print "+ *.txt\n";
    my %hash;
    open(IN, 'find . -name "*.txt" |') or die "Failed to run find: $!\n";
    while (<IN>) {
	chomp;
	s#^\./##;
	next unless s#/[^/]*\.txt$##;
	my $path = '';
	foreach (split(/\//)) {
	    $path .= $_ . '/';
	    next if $hash{$path};
	    $hash{$path} = 1;
	    print "+ $path\n";
	}
    }
    print "- *\n";

And use it like this:

  new-script ./source | rsync -avz --delete-excluded --exclude-from=- ./source/ ./dest

..wayne..


More information about the rsync mailing list