print "\t$0 [-dhirv] <zfs shapshot name> [filename]\n\n";
print " -d Display the lines that are different (diff output)\n";
print " -h Display this usage\n";
+ print " -m Use md5sum when checking for file differences";
print " -i Ignore files that don't exist in the snapshot (only necessary for recursing)\n";
print " -r Recursively diff every file in the snapshot (filename not required)\n";
print " -v Verbose mode\n\n";
"r!" => \$options{recurse},
"d!" => \$options{diff},
"i!" => \$options{ignore},
+ "m!" => \$options{md5sum},
"v!" => \$verbose
);
print "Recursive diff on $zfssnap\n" if $verbose;
$zfssnap =~ /(.+)\@(.+)/i;
+ if(($1 eq "") || ($2 eq "")) { die "-E- Invalid snapshot name\n"; }
my $fsname = "/" . $1;
my $snapname = $2;
if(! -d $fsname && $fsname =~ /\/\S+?(\/.*)/) { $fsname = $1; }
my $dir = tempdir( CLEANUP => 0 );
my ($fh, $filename) = tempfile( DIR => $dir );
+ print "-> Finding files in $fspath to compare against files in $snappath\n";
`find $fspath -name "*" -type f > $filename`;
+ print "-> Performing a diff operation on each file found\n";
+ my $num_files = `cat $filename | wc | awk '{print \$1}'`;
+
foreach my $file (<$fh>) {
chomp($file);
$file =~ /(.*)\/(.*)/;
next;
}
- # do the md5 sums
- my $orig = `$SSLPATH md5 $file`;
- my $snap = `$SSLPATH md5 $diff`;
- $orig =~ /[\s\S]+= (.+)/;
- my $sum1 = $1;
- $snap =~ /[\s\S]+= (.+)/;
- my $sum2 = $1;
- if ($sum1 ne $sum2) {
- print "** $file is different\n";
- print "** $orig** $snap" if $verbose;
+ if($options{md5sum}) {
+ # do the md5 sums
+ my $orig = `$SSLPATH md5 $file`;
+ my $snap = `$SSLPATH md5 $diff`;
+ $orig =~ /[\s\S]+= (.+)/;
+ my $sum1 = $1;
+ $snap =~ /[\s\S]+= (.+)/;
+ my $sum2 = $1;
+ if ($sum1 ne $sum2) {
+ print "** $file is different\n";
+ print "** $orig** $snap" if $verbose;
+ }
+ } else {
+ my $differ = system("diff \"$file\" \"$diff\" > /dev/null 2>&1");
+ if($differ) { print "** $file is different\n"; }
}
if ($options{diff}) {
- system("diff $file $diff");
+ system("diff \"$file\" \"$diff\"");
}
}
}
if(! -f $fspath) { print "-E- Cannot find source file: $fspath\n"; exit 1; }
if(! -f $snappath) { print "-E- Cannot find source file: $snappath\n"; exit 1; }
- my $orig = `$SSLPATH md5 $fspath`;
- my $snap = `$SSLPATH md5 $snappath`;
- $orig =~ /[\s\S]+= (.+)/;
- my $sum1 = $1;
- $snap =~ /[\s\S]+= (.+)/;
- my $sum2 = $1;
- if ($sum1 ne $sum2) {
- print "** Files are different\n";
- print "** $orig** $snap" if $verbose;
+ if($options{md5sum}) {
+ my $orig = `$SSLPATH md5 $fspath`;
+ my $snap = `$SSLPATH md5 $snappath`;
+ $orig =~ /[\s\S]+= (.+)/;
+ my $sum1 = $1;
+ $snap =~ /[\s\S]+= (.+)/;
+ my $sum2 = $1;
+ if ($sum1 ne $sum2) {
+ print "** Files are different\n";
+ print "** $orig** $snap" if $verbose;
+ }
+ } else {
+ my $differ = system("diff \"$fspath\" \"$snappath\" > /dev/null 2>&1");
+ if($differ) { print "** Files are different\n"; }
}
if ($options{diff}) {
- system("diff $fspath $snappath");
+ system("diff \"$fspath\" \"$snappath\"");
}
}