Eric Wilhelm - [EMAIL PROTECTED] wrote:
1. Why can't rsync's exclude syntax do this?
That implies that (if anything), dirvish should simply be trying to
provide a nicer way to manage include/exclude rules. However, maybe an
rsync tutorial would do the trick without any de-stabilization of the
as-yet-untested code.
Instead of hacking dirvish, I've written a perl pre-server script that
takes several paths as arguments, and creates rsync exclude rules to
correctly include only the given paths. It then adds those rules to
dirvish's exclude file, so rsync picks them up automatically. Using the
following in dirvish.conf (with pre-server all on one line):
tree: /
pre-server: /path/to/script/include_paths.pl /etc /root /var/lib/dhcp/
/var/lib/nfs /home/yklein/this\ is\ a\ long/test/
will result in the following added to the exclude file:
+ /etc
+ /root
+ /var
+ /var/lib
+ /var/lib/dhcp
+ /var
+ /var/lib
+ /var/lib/nfs
+ /home
+ /home/yklein
+ /home/yklein/this is a long
+ /home/yklein/this is a long/test
- /var/lib/*
- /var/*
- /var/lib/*
- /var/*
- /home/yklein/this is a long/*
- /home/yklein/*
- /home/*
- /*
And the image's tree directory contains:
etc/ home/ root/ var/
Like we wanted.
For each argument, the script adds include rules to build up the path
(/var/ /var/lib/ /var/lib/nfs/) and then exclude rules to exclude all
the unwanted stuff (the rest of /var/ and /var/lib/). All the includes
need to come before the excludes, since the first rule wins, and we
might want to include several things in /var before excluding all the
rest of it.
I've tested it on my system (and even tested it with paths containing
spaces), and it seems to work correctly. I'd appreciate it if others
could test and report their results with the script. I'm just an amateur
at perl coding, so I'm sure others can improve on this script.
Hope this helps,
Yoav Klein
#!/usr/bin/perl
#include_paths.pl - a script that takes several paths and creates
# a file of rsync include paths to include only the given paths
#
# By Yoav Klein, 2007-04-11
$out=$ENV{DIRVISH_DEST}.'/../exclude';
open OUT, ">>$out" or die "Cannot open $out for append :$!";
foreach $arg (@ARGV) {
# For each argument, we need to split apart the path, so we can build up to it
# /this
# /this/is
# /this/is/a
# and so on
# First we split the path into each of its elements, then we create a new array, in which we
# join together the path elements one at a time, then we make the final output, building
# in depth and then coming back out.
@path_elements = split '/', $arg;
# Need to undefine the path_building_up array, so we don't get old values left over
undef @path_building_up;
for (0..$#path_elements) {
$path_building_up[$_] = join '/', @path_elements[0..$_];
}
# Now let's build up the full path, element by element
for (1..$#path_building_up) {
print OUT '+ '.$path_building_up[$_]."\n";
}
}
# After outputing all the include's, we need to output the excludes
foreach $arg (@ARGV) {
@path_elements = split '/', $arg;
undef @path_building_up;
for (0..$#path_elements) {
$path_building_up[$_] = join '/', @path_elements[0..$_];
}
# we start one element before the end of @path_building_up and don't want to include
# the first (0) element
for (0..$#path_building_up-2) {
print OUT '- '.$path_building_up[$#path_building_up-1-$_].'/*'."\n";
}
}
# Add the final line, excluding everything else
print OUT "- \/*\n";
_______________________________________________
Dirvish mailing list
[EMAIL PROTECTED]
http://www.dirvish.org/mailman/listinfo/dirvish