[EMAIL PROTECTED] wrote:
> 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.
Brilliant!
I think a solution that avoids hacking Dirvish itself is much better
until such time as the feature can be incorporated in a full release.
I made a version with an extra hash, so it can avoid printing lines like
/var/lib twice.
Cheers, Dave
#!/usr/bin/perl
use strict;
use warnings;
#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
my $out=$ENV{DIRVISH_DEST}.'/../exclude';
open OUT, ">>$out" or die "Cannot open $out for append :$!";
# Remember what we already printed, so we don't print it twice
my %already_printed;
foreach my $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.
my @path_elements = split '/', $arg;
my @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) {
my $path = $path_building_up[$_];
next if $already_printed{$path};
print OUT '+ '.$path."\n";
$already_printed{$path} = 1;
}
}
undef %already_printed;
# After outputing all the include's, we need to output the excludes
foreach my $arg (@ARGV) {
my @path_elements = split '/', $arg;
my @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) {
my $path = $path_building_up[$#path_building_up-1-$_];
next if $already_printed{$path};
print OUT '- '.$path.'/*'."\n";
$already_printed{$path} = 1;
}
}
# Add the final line, excluding everything else
print OUT "- \/*\n";
_______________________________________________
Dirvish mailing list
[EMAIL PROTECTED]
http://www.dirvish.org/mailman/listinfo/dirvish