#!/usr/bin/perl -w # # comparesnaps - Daniel Smith, dls at daniel, org - 2003 or so... # # this takes two files with lines of the form: # use strict; no strict 'refs'; print "starting..."; sub get_checksums; sub dup_check; sub change_check; my (%first_filenames, %second_filenames); my (%first_dups, %second_dups); my (%first_mds, %second_mds); my (%first_cs, %second_cs); my ($first, $second); if ($#ARGV != 1) { die "usage: $0 prev_snapshot cur_snapshot\n"; } $first = $ARGV[0]; $second = $ARGV[1]; get_cksums($first, \%first_filenames, \%first_cs, \%first_dups); get_cksums($second, \%second_filenames, \%second_cs, \%second_dups); print "duplicates from snapshot: $first\n"; dup_check(\%first_filenames, \%first_dups); print "duplicates from snapshot: $second\n"; dup_check(\%second_filenames, \%second_dups); change_check(\%first_cs, \%second_cs); exit; sub get_cksums { my $fn = shift; my $fn_ref = shift; my $cs_ref = shift; my $dup_ref = shift; my ($cksum, $filename); open(CKSUM_FILE, "< $fn") || die "unable to read checksum file \"$fn\": $!\n"; while () { chop; ($cksum, $filename) = split; $$fn_ref{$cksum} .= "$cksum $filename\n"; $$cs_ref{$filename} .= "$cksum $filename\n"; $$dup_ref{$cksum}++; } } sub dup_check { my $compare_ref = shift; my $dup_ref = shift; my ($i); foreach $i (keys %$dup_ref) { if ($$dup_ref{$i} > 1) { print "$$compare_ref{$i}\n"; } } } sub change_check { my $first_cs_ref = shift; my $second_cs_ref = shift; my ($i); foreach $i (keys %$second_cs_ref) { if (! $$first_cs_ref{$i}) { print "new file: $$second_cs_ref{$i}\n"; next; } if ($$second_cs_ref{$i} !~ $$first_cs_ref{$i}) { print "changed file: $$second_cs_ref{$i}\n"; } } }