#================================================================================= # rollbackchecker by Jasper Kuria (Nov 11, 2005) # # Script to parse repadmin output and determine if we have a USN rollback # # Usage: perl rollbackchecker # # is generated using: # # repadmin /showutdvec * dc=,dc= #================================================================================= $dcCount = 0; $repadminPattern = "repadmin running command \/showutdvec"; $dcUSNPattern = "@ USN +[0-9]+ @"; $rollBackFound = 0; # First pass to build up the (DC => Self USN) table open(FILE, $ARGV[0]) or die; while($line = ) { if ($line =~ /$repadminPattern/o) { $currentDC = &GetCurrentDc($line); next; } if ($line =~ /$dcUSNPattern/o) { &AddDcUSNToTable($currentDC, $line); } } &PrintDcUSNTable; # Second pass to check if for a given DC, some other DC has a higher USN for it. open(FILE, $ARGV[0]) or die; while($line = ) { if ($line =~ /$repadminPattern/) { $currentDC = &GetCurrentDc($line); next; } if ($line =~ /$dcUSNPattern/) { &CheckAndReportRollBack($currentDC, $line); } } # report no rollbacks if (!$rollBackFound) { print "\nNo USN rollbacks were found\n"; } #subroutines sub GetCurrentDc { @tokens = split(/ +/, $line); # split according to spaces $lastToken = $tokens[@tokens - 1]; @fqdnTokens = split(/\./, $lastToken); $dcName = @fqdnTokens[0]; $currentDc = uc ($dcName); #convert to uppercase for comparison } sub CheckAndReportRollBack { @tokens = split(/\s+/, $line); $usn = $tokens[3]; @fqdnTokens = split(/\\/, $tokens[0]); $dcToCheck = uc($fqdnTokens[1]); if ($selfUSN = $dcUSNTable{$dcToCheck}) #does the DC have an entry in the table { if ($usn > $selfUSN) { $rollBackFound = 1; print "\n---------- rollback -----------------\n"; print ("DC $dcToCheck may have experienced a USN rollback. "); print("It's Self Highest USN = $selfUSN but the remote DC $currentDC "); print("has a USN = $usn for $dcToCheck that is higher than what $dcToCheck has for itself\n"); } } } sub AddDcUSNToTable { @tokens = split(/\s+/, $line); $usn = $tokens[3]; @fqdnTokens = split(/\\/, $tokens[0]); $dcToCheck = uc($fqdnTokens[1]); #convert to uppercase if ($dcToCheck eq $currentDc) { $dcUSNTable{$currentDc} = $usn; $dcCount++; } } sub PrintDcUSNTable { print "\nrepadmin /showutdvec ran successfully on $dcCount DCs\n\n"; print "DC Name Self Highest USN\n"; print "================= ==================\n"; $num = 1; while (($dc, $selfUSN) = each(%dcUSNTable)) { print ("$num. $dc $selfUSN\n"); $num++; } }