From: Alan J. Pippin Date: Sat, 8 Mar 2008 05:47:24 +0000 (-0700) Subject: Added script that can be used to diff files between different snapshots. X-Git-Url: http://git.pippins.net/embedvideo/.git/%22%22.%24thumbnail.%22/%7Blink_visit%7D?a=commitdiff_plain;h=cf5e9c6fa15fb2c337c5d74ef6bd92092cb2e709;p=zfs-nexenta%2F.git Added script that can be used to diff files between different snapshots. --- diff --git a/zfs-diff b/zfs-diff index 44f355c..fe857be 100755 --- a/zfs-diff +++ b/zfs-diff @@ -12,6 +12,7 @@ sub print_usage { print "\t$0 [-dhirv] [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"; @@ -43,6 +44,7 @@ GetOptions("h" => \$options{help}, "r!" => \$options{recurse}, "d!" => \$options{diff}, "i!" => \$options{ignore}, + "m!" => \$options{md5sum}, "v!" => \$verbose ); @@ -65,6 +67,7 @@ sub recurse_diff { 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; } @@ -80,8 +83,12 @@ sub recurse_diff { 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 =~ /(.*)\/(.*)/; @@ -93,19 +100,24 @@ sub recurse_diff { 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\""); } } } @@ -134,17 +146,22 @@ sub diff_single_file { 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\""); } }