#!/bin/bash # # $Header: /CVSROOT/public/scylla-charybdis/md5backup/bin/check.sh,v 1.5 2005/03/02 23:32:11 tino Exp $ # # Run this script in the directory (atop out/) # to verify if the backed up files are still valid. # # This script is designed to be interrupted anywhere # at any time and restart work from where it left. # So if a "check.list" exists, it is rerun. # To be sure everything is OK run it with argument -f # # $Log: check.sh,v $ # Revision 1.5 2005/03/02 23:32:11 tino # first version for multi filestore # # Revision 1.4 2004/10/05 02:03:17 tino # You can give the path to the script now # # Revision 1.3 2004/04/24 01:10:46 tino # Intermediate version, I start to implement linked file store now # # Revision 1.2 2004/01/07 12:05:09 tino # Scripts improved, some spelling corrections, and CVS headers added. # md5backup.c now has a sanity check which slows down things factor 10. rm -f check.fail.tmp if [ ! -s "check.list" ] || { [ .-f = ".$1" ] && shift; } then echo "part1:a: building file list" > check.list.tmp [ -f check.list.old ] || >> check.list.old count=-`wc -l < check.list.old | tr -d ' '` tail -f check.list.tmp 2>&1 | while read a do let count=count+1 echo -n "$count " done & bgpid="$!" find "${1:-out}"/* -type f -name '*.md5' -print >> check.list.tmp kill $bgpid echo "part1:b: sorting file list" sort check.list.tmp > check.list || exit 1 sync > check.list.tmp rerun=false else echo "part1: reusing file list" rerun=: fi # As this is designed to be stopped anywhere we have to sort first if [ ! -s check.ok ] then fullrun=: echo "part2: creating check.ok" > check.ok else fullrun=false echo "part2:a: sorting check.ok (delete this for full new check)" sort check.ok > check.ok.tmp || exit 1 if ! cmp -s check.ok check.ok.tmp then echo "part2:b: oklist changed" sync # Sanity check. I really don't trust. sort check.ok | cmp - check.ok.tmp || exit 1 mv -f check.ok.tmp check.ok fi fi echo "part3:a: locating new files" > check.fail.tmp comm -13 check.ok check.list > check.todo count=`wc -l < check.todo` echo "part3:b: checking $count files" while read a do let count=count-1 echo -n "$count " case "$a" in *.md5) processor="cat";; # Those two might show up in future *.md5.gz) processor="gzcat";; *.md5.bz2) processor="bzcat";; # Ignore unknown stuff *) echo "don't know hot to handle $a" >&2; continue;; esac sum="`$processor "$a" | md5sum`" if [ ".${sum// *}" = ".`basename "${a//.*}"`" ] then echo "$a" >> check.ok else echo "$a" >> check.fail.tmp echo "failed: $a" >&2 fi done < check.todo echo "part4: syncing filesystems" sync [ -f check.fail ] && mv -f check.fail check.fail.old if [ -s check.fail.tmp ] then echo "part4:b: `wc -l < check.fail.tmp` mismatches found" echo "MD5 mismatches found, see file check.fail!" >&2 mv -f check.fail.tmp check.fail echo -n "" ret=2 else if $rerun then echo "part4:b: please rerun to be safe everything is ok" echo "OK but rerun" >&2 ret=3 elif $fullrun then echo "part4:b: MD5 sums ok (full run)" ret=0 else echo "part4:b: MD5 sums ok (incremental run)" ret=0 fi fi sync mv -f check.list check.list.old sync