#!/bin/bsh # # Written by: # Brent L. Bates # ViGYAN, Inc. # 30 Research Drive # Hampton, VA 23666-2315 # blbates@vigyan.com # #set -x #set -v if [ ${#} -ne 2 ]; then echo "Useage: $0 hostname tape_number" exit fi TAPELABEL='Backups:ViGYAN:'$1':Tape_'$2':Level_0' TAPEHOST_OS=`uname -s` if [ ${TAPEHOST_OS} = 'IRIX' -o ${TAPEHOST_OS} = 'IRIX64' ]; then # # SGI # TAPE=/dev/nrtapec TAPE_STATUS='mt -f ${TAPE} status 2>&1 | grep Media |sed -e "s/^.*Media.*:[ ]*//" |sed -e "s/[ ][ ]*.*//' UNLOAD='mt -f ${TAPE} rewind ; mt -f ${TAPE} offline ; if [ `eval ${TAPE_STATUS}` != 'Not' ]; then mt -f ${TAPE} unload; fi' if [ x`eval ${TAPE_STATUS}` != 'xNot' ]; then # # Partition Tape # mt -f ${TAPE} rewind mt -f ${TAPE} mkpart 1 # # Move to header partition # mt -f ${TAPE} sppart 1 mt -f ${TAPE} rewind TAPE_UNLOADED="No" else echo "No tape loaded." TAPE_UNLOADED="Yes" fi elif [ ${TAPEHOST_OS} = 'Linux' ]; then # # Linux # TAPE=/dev/nst0 TAPE_STATUS='mt -f ${TAPE} status 2>&1 | grep DR_OPEN |tr "[\ ]" "[\n]" |grep DR_OPEN' UNLOAD='echo "Rewinding Tape." ; mt -f ${TAPE} rewind ; echo "Offlining Tape." ; mt -f ${TAPE} offline ; if [ 'x'`eval ${TAPE_STATUS}` != 'xDR_OPEN' ]; then mt -f ${TAPE} offline; fi' if [ x`eval ${TAPE_STATUS}` != 'xDR_OPEN' ]; then # # Make sure tape drive is in proper mode. # echo "Rewinding Tape." mt -f ${TAPE} rewind echo "Setting tape parameters: stsetoptions scsi2logical can-partitions" mt -f ${TAPE} stsetoptions scsi2logical can-partitions echo "Clearing tape parameters: stclearoptions async-writes" mt -f ${TAPE} stclearoptions async-writes echo "Setting: setblk 0 (Variable block size)" mt -f ${TAPE} setblk 0 echo "Setting: defcompression 1" mt -f ${TAPE} defcompression 1 if [ `uname -r` = '2.2.14-12' ]; then echo "Setting: datcompression 1" mt -f ${TAPE} datcompression 1 fi echo "Setting: compression 1" mt -f ${TAPE} compression # # Partition Tape # echo "Making partition." mt -f ${TAPE} mkpartition 1 # # Move to header partition # echo "Moving to partition 1." mt -f ${TAPE} setpartition 1 echo "Rewinding Tape." mt -f ${TAPE} rewind TAPE_UNLOADED="No" else echo "No tape loaded." TAPE_UNLOADED="Yes" fi else # # SunOS # TAPE=/dev/exabyte UNLOAD="mt -f ${TAPE} rewind; mt -f ${TAPE} offline" mt -f ${TAPE} rewind fi if [ ${TAPE_UNLOADED} != 'Yes' ]; then # # Lable Tape # echo $TAPELABEL | dd of=${TAPE} bs=1k cbs=1k conv=block mt -f $TAPE rewind # # Check Lable # dd if=${TAPE} bs=1k cbs=1k conv=unblock eval ${UNLOAD} fi