3 # $Id: amverify.sh.in,v 1.7.2.13.4.5.2.6 2003/10/24 13:44:49 martinea Exp $
5 # (C) 1996 by ICEM Systems GmbH
6 # Author: Axel Zinser (fifi@icem.de)
8 # amverify: check amanda tapes and report errors
12 exec_prefix=@exec_prefix@
14 libexecdir=@libexecdir@
16 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb
19 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
20 if [ "$USE_VERSION_SUFFIXES" = "yes" ]; then
26 # If the shell/system echo support \r and \c, use them to write some
27 # status messages over the top of each other as things progress, otherwise
28 # use a normal echo and let them go on new lines. Define $Echoe to be
29 # an echo that goes to stderr. In the code, $Echoe is used and it may
30 # be either echoe or echone, the latter being code that knows about echon.
32 t=`echo "abc\r\c" | wc -c`
45 newelen=`expr "$1" : '.*'`
47 while [ $newelen -lt $elen ]; do
51 echo "$1""$blanks\r\c"
67 $AMGETCONF $CONFIG $1 2>/dev/null | grep -v BUGGY
71 if [ -f $REPORT -a X"$REPORTTO" != X"" ]; then
73 echo "Tapes: $TAPELIST"
74 if [ -s $DEFECTS ]; then
78 echo "No errors found!"
84 ) | $MAIL -s "$ORG AMANDA VERIFY REPORT FOR$TAPELIST" $REPORTTO
89 # This function is called to process one dump image. Standard input is
90 # the dump image. We parse the header and decide if it is a GNU tar
91 # dump or a system dump. Then we do a catalog operation to /dev/null
92 # and finally a "cat" to /dev/null to soak up whatever data is still in
95 # In the case of a system restore catalogue, this does not fully check
96 # the integrity of the dump image because system restore programs stop
97 # as soon as they are done with the directories, which are all at the
98 # beginning. But the trailing cat will at least make sure the whole
105 # The goal here is to collect the first 32 KBytes and save the
106 # first line. But the pipe size coming in to us from amrestore
107 # is highly system dependent and "dd" does not do reblocking.
108 # So we pick a block size that is likely to always be available in
109 # the pipe and a count to take it up to 32 KBytes. Worst case,
110 # this could be changed to "bs=1 count=32k". We also have to
111 # soak up the rest of the output after the "head" so an EPIPE
112 # does not go back and terminate the "dd" early.
115 HEADER=`$DD bs=512 count=64 | ( sed 1q ; cat > /dev/null )`
118 if [ X"$HEADER" = X"" ]; then
119 echo "** No header" > $TEMP/errors
124 if [ X"$1" = X"program" -a X"$2" != X"" ]; then
125 if [ X"$TAR" != X"" \
126 -a \( X"`basename $2`" = X"`basename $TAR`" \
127 -o X"`basename $2`" = X"gtar" \
128 -o X"`basename $2`" = X"gnutar" \
129 -o X"`basename $2`" = X"tar" \) ]; then
132 elif [ X"$TAR" != X"" \
133 -a X"$SAMBA_CLIENT" != X"" \
134 -a X"$2" = X"$SAMBA_CLIENT" ]; then
137 elif [ X"$DUMP" != X"" -a X"$2" = X"$DUMP" ]; then
139 if [ $IS_AIX -eq 1 ]; then
144 elif [ X"$VDUMP" != X"" -a X"$2" = X"$VDUMP" ]; then
147 elif [ X"$VXDUMP" != X"" -a X"$2" = X"$VXDUMP" ]; then
150 elif [ X"$XFSDUMP" != X"" -a X"$2" = X"$XFSDUMP" ]; then
152 ARGS="-t -v silent -"
154 echo "** Cannot do $2 dumps" > $TEMP/errors
155 result=999 # flag as not really an error
158 echo "** Cannot find dump type" > $TEMP/errors
161 if [ X"$CMD" != X"" ]; then
163 $CMD $ARGS > /dev/null 2> $TEMP/errors
166 echo "** Cannot execute $CMD" > $TEMP/errors
169 cat >/dev/null # soak up the rest of the image
176 # CONFIG_DIR directory in which the config file resides
177 # AMRESTORE full path name of amrestore
178 # AMGETCONF full path name of amgetconf
179 # AMTAPE full path name of amtape
180 # TAR ditto for GNU-tar
181 # SAMBA_CLIENT ditto for smbclient
182 # DUMP ditto for the system dump program
183 # RESTORE ditto for the system restore program
184 # VDUMP ditto for the system dump program
185 # VRESTORE ditto for the system restore program
186 # VXDUMP ditto for the system dump program
187 # VXRESTORE ditto for the system restore program
188 # XFSDUMP ditto for the system dump program
189 # XFSRESTORE ditto for the system restore program
192 # MTF flag given to MT to specify tape device: -f or -t
194 # IS_AIX true if this is an AIX system
196 CONFIG_DIR=@CONFIG_DIR@
197 libexecdir=$libexecdir
199 AMRESTORE=$sbindir/amrestore$SUF
200 AMGETCONF=$sbindir/amgetconf$SUF
201 AMTAPE=$sbindir/amtape$SUF
203 SAMBA_CLIENT=@SAMBA_CLIENT@
209 VXRESTORE=@VXRESTORE@
211 XFSRESTORE=@XFSRESTORE@
212 if [ -x $sbindir/ammt$SUF ]; then
215 elif [ -x "@MT@" ]; then
219 $Echoe "amverify$SUF mt program not found"
222 if [ -x $sbindir/amdd$SUF ]; then
224 elif [ -x "@DD@" ]; then
227 $Echoe "amverify$SUF dd program not found"
231 if [ X"`/bin/uname -s 2>/dev/null`" = X"AIX" ]; then
234 # The AIX "mt stat" function does not really do anything w.r.t.
235 # checking the drive for ready, and in fact, will fail under
236 # some conditions (e.g. if the tape "file" is a symlink to the
237 # real device). We let the rewind do the equivalent since all
238 # we use this for is to wait for device ready.
243 DEVICE_READY='$MT $MTF $DEVICE stat'
251 [ X"$CONFIG" = X"" ] \
252 && $Echoe "usage: amverify$SUF <config> [slot [ runtapes ] ]" \
255 AMCONFIG=$CONFIG_DIR/$CONFIG/amanda.conf
257 && $Echoe "Cannot find config file $AMCONFIG" \
260 TPCHANGER=`getparm tpchanger`
261 if [ X"$TPCHANGER" = X"" ]; then
262 $Echoe "No tape changer..."
263 DEVICE=`getparm tapedev`
264 [ X"$DEVICE" = X"" ] \
265 && $Echoe "No tape device..." \
267 $Echoe "Tape device is $DEVICE..."
270 CHANGER_SLOT=${2:-current}
271 $Echoe "Tape changer is $TPCHANGER..."
272 SLOTS=${3:-`getparm runtapes`}
273 [ X"$SLOTS" = X"" ] && SLOTS=1
274 if [ $SLOTS -eq 1 ]; then
279 $Echoe "$SLOTS slot${p}..."
284 # check the accessability
286 [ X"$TAR" != X"" -a ! -x "$TAR" ] \
287 && $Echoe "GNU tar not found: $TAR"
288 [ X"$DUMP" != X"" -a \( X"$RESTORE" = X"" -o ! -x "$RESTORE" \) ] \
289 && $Echoe "System restore program not found: $RESTORE"
290 [ X"$VDUMP" != X"" -a \( X"$VRESTORE" = X"" -o ! -x "$VRESTORE" \) ] \
291 && $Echoe "System restore program not found: $VRESTORE"
292 [ X"$VXDUMP" != X"" -a \( X"$VXRESTORE" = X"" -o ! -x "$VXRESTORE" \) ] \
293 && $Echoe "System restore program not found: $VXRESTORE"
294 [ X"$XFSDUMP" != X"" -a \( X"$XFSRESTORE" = X"" -o ! -x "$XFSRESTORE" \) ] \
295 && $Echoe "System restore program not found: $XFSRESTORE"
296 [ ! -x $AMRESTORE ] \
297 && $Echoe "amrestore not found: $AMRESTORE" \
300 REPORTTO=`getparm mailto`
301 if [ X"$REPORTTO" = X"" ]; then
302 $Echoe "No notification by mail!"
304 $Echoe "Verify summary to $REPORTTO"
308 if [ X"$ORG" = X"" ]; then
309 $Echoe "No org in amanda.conf -- using $CONFIG"
316 # TEMP directory for temporary tar archives and stderr
317 # DEFECTS defect list
318 # REPORT report for mail
320 if [ ! -d @AMANDA_TMPDIR@ ]; then
321 $Echoe "amverify: directory @AMANDA_TMPDIR@ does not exist."
325 cd @AMANDA_TMPDIR@ || exit 1
327 TEMP=@AMANDA_TMPDIR@/amverify.$$
328 trap 'rm -fr $TEMP' 0
329 if ( umask 077 ; mkdir $TEMP ) ; then
332 $Echoe "Cannot create $TEMP"
335 DEFECTS=$TEMP/defects; rm -f $DEFECTS
336 REPORT=$TEMP/report; rm -f $REPORT
338 EXITSTAT=$TEMP/amrecover.exit; rm -rf $EXITSTAT
340 trap 'report "aborted!"; echo "aborted!" >> $DEFECTS; sendreport; rm -fr $TEMP; exit 1' 1 2 3 4 5 6 7 8 10 12 13 14 15
342 $Echoe "Defects file is $DEFECTS"
343 report "amverify $CONFIG"
347 # ----------------------------------------------------------------------------
349 while [ $SLOT -lt $SLOTS ]; do
350 SLOT=`expr $SLOT + 1`
352 # Tape Changer: dial slot
354 if [ X"$TPCHANGER" != X"" ]; then
355 report "Loading ${CHANGER_SLOT} slot..."
356 $AMTAPE $CONFIG slot $CHANGER_SLOT > $TEMP/amtape.out 2>&1
357 THIS_SLOT=$CHANGER_SLOT
359 RESULT=`grep "changed to slot" $TEMP/amtape.out`
360 [ X"$RESULT" = X"" ] \
361 && report "** Error loading slot $THIS_SLOT" \
362 && report "`cat $TEMP/amtape.out`" \
363 && cat $TEMP/amtape.out >> $DEFECTS \
365 DEVICE=`$AMTAPE $CONFIG device`
367 report "Using device $DEVICE"
368 $Echon "Waiting for device to go ready..."
369 until eval $DEVICE_READY >/dev/null 2>&1; do
372 $Echon "Rewinding..."
373 until $MT $MTF $DEVICE rewind; do
376 $Echon "Processing label..."
377 $DD if=$DEVICE count=1 bs=@MAXTAPEBLOCKSIZE@k 2> $TEMP/errors > $TEMP/header
378 [ ! -s $TEMP/header ] \
379 && report "** Error reading label on tape" \
380 && cat $TEMP/errors >> $DEFECTS \
382 TAPENDATE=`sed 1q < $TEMP/header | grep '^AMANDA: TAPESTART'`
383 [ X"$TAPENDATE" = X"" ] \
384 && report "** No amanda tape in slot" \
392 report "Volume $VOLUME, Date $DWRITTEN"
393 [ X"$DWRITTEN" = X"0" -o X"$DWRITTEN" = X"X" ] \
394 && report "Fresh tape. Skipping..." \
396 TAPELIST="$TAPELIST $VOLUME"
397 $Echon "Rewinding..."
398 until $MT $MTF $DEVICE rewind; do
403 while [ $ERG = 0 ]; do
404 if [ $Echon = echon ]; then
405 $Echon "Waiting for device to go ready..."
407 until eval $DEVICE_READY >/dev/null 2>&1; do
410 if [ $Echon = echon ]; then
413 RESULT=`$AMRESTORE -h -p $DEVICE 2> $TEMP/amrestore.out \
414 | doonefile 2> $TEMP/onefile.errors`
415 FILE=`grep restoring $TEMP/amrestore.out \
416 | sed 's/^.*restoring //'`
417 EOF=`grep "reached end of tape" $TEMP/amrestore.out`
418 # amrestore: 0: restoring sundae._mnt_sol1_usr.19961127.1
419 if [ X"$FILE" != X"" -a X"$RESULT" = X"0" ]; then
420 report "Checked $FILE"
421 elif [ X"$FILE" != X"" -a X"$RESULT" = X"999" ]; then
422 report "Skipped $FILE (`cat $TEMP/errors`)"
423 elif [ -n "$EOF" ]; then
424 report "End-of-Tape detected."
427 report "** Error detected ($FILE)"
428 echo "$VOLUME ($FILE):" >>$DEFECTS
429 [ -s $TEMP/amrestore.out ] \
430 && report "`cat $TEMP/amrestore.out`" \
431 && cat $TEMP/amrestore.out >>$DEFECTS
432 [ -s $TEMP/errors ] \
433 && report "`cat $TEMP/errors`" \
434 && cat $TEMP/errors >>$DEFECTS
435 [ -s $TEMP/onefile.errors ] \
436 && report "`cat $TEMP/onefile.errors`" \
437 && cat $TEMP/onefile.errors >>$DEFECTS
438 ERRORS=`expr $ERRORS + 1`
440 && report "Too many errors." \
444 $Echon "Rewinding..."
445 until $MT $MTF $DEVICE rewind; do
450 $TEMP/amrestore.out \
456 && $Echoe "Errors found: " \