dotar
:
# -------------------------------------------------------------------
# dotar
# Script to tar MSTI data to multi-tape DAT tape.
# To run script in background enter <sh dotar &>
# LRE 4/18/95
# -------------------------------------------------------------------
#
# Do some housekeeping first.
#
tartime=`date`
echo "Starting dotar at $tartime" > dotar.log
cp -p tar.log tar.log.bak 2>> dotar.log
cp -p dotar.log dotar.log.bak 2>> dotar.log
rm -f dotar.log 2>> dotar.log
cp -p tar.restore tar.restore.bak 2>> dotar.log
rm -f tar.restore 2>> dotar.log
#
# initialize
#
tapenum=1
tarstat=1
#
# Start main loop
#
while [ $tarstat != 0 ]
do
tar cvf /dev/rmt/0c /da/msti 1> tar.lst.tmp 2>> dotar.log
tarstat=$?
# status will be zero for last tape
if [ $tarstat != 0 ]
then
# remove the incomplete tar file from the list
set `wc -l tar.lst.tmp` 2>> dotar.log
head -`expr $1 - 1` tar.lst.tmp 1> tar.lst 2>> dotar.log
# get the transferred files out of the tar directory
chmod 0666 tar.log
cat tar.lst | while read line
do
# if directory then make a directory
if [ -d "/$line" ]
then
echo "making directory /da/tar/$line" >> dotar.log
mkdir /da/tar/$line 1>> dotar.log 2>> dotar.log
# if file move out of tar path
elif [ -f "/$line" ]
then
echo " moving /$line to /da/tar/$line" >> dotar.log
mv -f "/$line" "/da/tar/$line" 1>> dotar.log 2>> dotar.log
# if neither then notify
else
echo "$line not directory or file" >> dotar.log 2>> dotar.log
fi
# add to tar master list
tartime=`date`
echo "Tape Num $tapenum $tartime $line " >> tar.log
done
# make a copy to restore files back to regular place when done
cat tar.lst >> tar.restore
# go to next tape
mt -f /dev/rmt/0c offline 1>> dotar.log 2>> dotar.log
tapenum=`expr $tapenum + 1`
# Wait for next tape mounted
mtstat=1
mttrys=0
while [ $mtstat != 0 ]
do
sleep 10
mt -f /dev/rmt/0c status 1>> dotar.log 2>> dotar.log
mtstat=$?
mttrys=`expr $mttrys + 1`
if [ $mttrys = 12 ]
then
echo "Error mounting new tape $tapenum - exiting"
echo "Error mounting new tape $tapenum - exiting" >> dotar.log
exit
fi
done
# else status = 0
else
chmod 0666 tar.log
cat tar.lst.tmp | while read line
do
# add to tar master list
tartime=`date`
echo "Tape Num $tapenum $tartime $line " >> tar.log
done
# end of if status != 0
fi
# end of main loop
chmod 0444 tar.log
# debug
# tarstat=0
done
# Put the files back where they were
cat tar.restore | while read line
do
if [ -f "/da/tar/$line" ]
then
echo "restoring /da/tar/$line to /$line" >> dotar.log
mv -f "/da/tar/$line" "/$line" 1>> dotar.log 2>> dotar.log
fi
done
tartime=`date`
echo "Done with MSTI dotar $tartime" >> dotar.log