Imported Debian patch 2.5.2p1-2
[debian/amanda] / server-src / amverify.sh.in
index 6608ac9360171674319d0a0850e9d1ca742bf2ec..21e111d4a7ba7441adaa3df6eb82e0465aab003b 100644 (file)
@@ -1,6 +1,6 @@
-#! /bin/sh
+#! @SHELL@
 #
-#      $Id: amverify.sh.in,v 1.7.2.13.4.5.2.6 2003/10/24 13:44:49 martinea Exp $
+#      $Id: amverify.sh.in,v 1.38 2006/07/25 19:00:56 martinea Exp $
 #
 # (C) 1996 by ICEM Systems GmbH
 # Author: Axel Zinser (fifi@icem.de)
@@ -64,7 +64,7 @@ report() {
 }
 
 getparm() {
-       $AMGETCONF $CONFIG $1 2>/dev/null | grep -v BUGGY
+       $AMGETCONF $CONFIG $1 2>/dev/null
 }
 
 sendreport() {
@@ -119,8 +119,8 @@ doonefile() {
                echo "** No header" > $TEMP/errors
        else
                set X $HEADER
-               shift
-               shift 9
+               # XXX meh, while[] is dangerous, what about a bad header?
+               while [ X"$1" != X"program" ]; do shift; done
                if [ X"$1" = X"program" -a X"$2" != X"" ]; then
                        if [ X"$TAR" != X"" \
                             -a \( X"`basename $2`" = X"`basename $TAR`" \
@@ -158,7 +158,13 @@ doonefile() {
                        echo "** Cannot find dump type" > $TEMP/errors
                fi
        fi
-       if [ X"$CMD" != X"" ]; then
+       echo $CMD > $TEMP/onefile.cmd
+       if [ X"`echo $HEADER | grep '^AMANDA: SPLIT_FILE'`" != X"" ]; then
+           result=500
+           set X $HEADER
+           shift 7
+           echo $1 | cut -f7 -d' ' > $TEMP/onefile.partnum
+       elif [ X"$CMD" != X"" ]; then
                if [ -x $CMD ]; then
                        $CMD $ARGS > /dev/null 2> $TEMP/errors
                        result=$?
@@ -346,6 +352,7 @@ report ""
 
 # ----------------------------------------------------------------------------
 
+SPLIT_DUMPS= # this will keep track of split dumps that we'll tally later
 while [ $SLOT -lt $SLOTS ]; do
        SLOT=`expr $SLOT + 1`
        #
@@ -366,11 +373,31 @@ while [ $SLOT -lt $SLOTS ]; do
        fi
        report "Using device $DEVICE"
        $Echon "Waiting for device to go ready..."
-       until eval $DEVICE_READY >/dev/null 2>&1; do
+       count=1800
+       until eval $DEVICE_READY > $TEMP/ammt.out 2>&1; do
+               [ count -lt 0 ] \
+                       && report "Device not ready" \
+                       && report "`cat $TEMP/ammt.out`" \
+                       && report cat $TEMP/ammt.out >> $DEFECTS \
+                       && break;
                sleep 3
+               count=`expr $count - 3`
        done
        $Echon "Rewinding..."
-       until $MT $MTF $DEVICE rewind; do
+       ERRORS=0
+       until $MT $MTF $DEVICE rewind > $TEMP/ammt.out 2>&1; do
+               RESULT=`grep "No medium found" $TEMP/ammt.out`
+               [ X"$RESULT" != X"" ] \
+                       && report "** Error rewinding tape" \
+                       && report "`cat $TEMP/ammt.out`" \
+                       && cat $TEMP/ammt.out >> $DEFECTS \
+                       && break
+               ERRORS=`expr $ERRORS + 1`
+               [ $ERRORS -gt 100 ] \
+                       && report "** Error rewinding tape" \
+                       && report "`cat $TEMP/ammt.out`" \
+                       && cat $TEMP/ammt.out >> $DEFECTS \
+                       && break
                sleep 3
        done
        $Echon "Processing label..."
@@ -404,8 +431,15 @@ while [ $SLOT -lt $SLOTS ]; do
                if [ $Echon = echon ]; then
                        $Echon "Waiting for device to go ready..."
                fi
-               until eval $DEVICE_READY >/dev/null 2>&1; do
+               count=1800
+               until eval $DEVICE_READY > $TEMP/ammt.out 2>&1; do
+                       [ count -lt 0 ] \
+                               && report "Device not ready" \
+                               && report "`cat $TEMP/ammt.out`" \
+                               && report cat $TEMP/ammt.out >> $DEFECTS \
+                               && break;
                        sleep 3
+                       count=`expr $count - 3`
                done
                if [ $Echon = echon ]; then
                        $Echon "Reading..."
@@ -415,14 +449,25 @@ while [ $SLOT -lt $SLOTS ]; do
                FILE=`grep restoring $TEMP/amrestore.out \
                        | sed 's/^.*restoring //'`
                EOF=`grep "reached end of tape" $TEMP/amrestore.out`
+               EOI=`grep "reached end of information" $TEMP/amrestore.out`
                # amrestore:   0: restoring sundae._mnt_sol1_usr.19961127.1
                if [ X"$FILE" != X"" -a X"$RESULT" = X"0" ]; then
                        report "Checked $FILE"
+               elif [ X"$FILE" != X"" -a X"$RESULT" = X"500" ]; then
+                       report "Skipped `cat $TEMP/onefile.cmd` check on partial dump $FILE"
+                       dump="`echo $FILE | cut -d'.' -f'1,2,3,4'`"
+                       cat $TEMP/onefile.partnum >> $TEMP/$dump.parts
+                       if [ X"`echo $SPLIT_DUMPS | grep $dump`" = X"" ]; then
+                           SPLIT_DUMPS="$dump $SPLIT_DUMPS"
+                       fi
                elif [ X"$FILE" != X"" -a X"$RESULT" = X"999" ]; then
                        report "Skipped $FILE (`cat $TEMP/errors`)"
                elif [ -n "$EOF" ]; then
                        report "End-of-Tape detected."
                        break
+               elif [ -n "$EOI" ]; then
+                        report "End-of-Information detected."
+                        break
                else
                        report "** Error detected ($FILE)"
                        echo "$VOLUME ($FILE):" >>$DEFECTS
@@ -449,6 +494,8 @@ while [ $SLOT -lt $SLOTS ]; do
              $TEMP/amtape.out \
              $TEMP/amrestore.out \
              $TEMP/errors \
+             $TEMP/onefile.cmd \
+             $TEMP/onefile.partnum \
              $TEMP/onefile.errors
 done
 
@@ -456,6 +503,44 @@ done
        && $Echoe "Errors found: " \
        && cat $DEFECTS
 
+# Work out whether any split dumps we saw had all their parts
+for dump in $SPLIT_DUMPS;do
+    report ""
+    numparts=0
+    max=0
+    max_known=0
+    missing=0
+    # figure out 
+    for part in `cat $TEMP/$dump.parts`;do
+       cur="`echo $part | cut -d/ -f1`"
+       max="`echo $part | cut -d/ -f2`"
+       if [ $max != "UNKNOWN" ]; then
+           numparts=$max
+           max_known=1
+           break;
+       fi
+       if [ $cur -gt $numparts ]; then
+           numparts=$cur
+       fi
+    done
+    report "Split dump $dump should have $numparts total pieces"
+    if [ $max_known != 1 ]; then
+       report "NOTE: Header field for total pieces was UNKNOWN, $numparts is best guess"
+    fi
+    part=1
+    while [ $part -lt $numparts ];do
+       part=`expr $part + 1`
+       if [ X"`grep \"^$part/\" $TEMP/$dump.parts`" = X"" ];then
+           report "Spanning chunk part $part is missing!"
+           missing=`expr $missing + 1`
+       fi
+    done
+    if [ $missing = 0 ];then
+       report "All parts found"        
+    fi
+    rm -f $TEMP/$dump.parts
+done
+
 sendreport
 
 exit 0