
# save a system memory image dump from /dev/swap to tape or floppy

# shell variables used:
#
#       DEV     "f" = floppy; "t" = tape
#
#       OF      output device file used by dd
#       BS      block size used by dd, in 512 byte units
#       COUNT   number of blocks to be copied by dd
#       SKIP    number of blocks for dd to skip
#
#       NB      number of BS size blocks on tape/disk
#       N       number of BS size blocks of memory to copy
#

echo 'There may be a system dump memory image in the swap device.'
while :
do
	echo 'Do you want to save it? (y/n)> \c'
	read ans
	case $ans in
	  y )   break ;;
	  n )   exit 0 ;;
	esac
	echo '???'
done

while :
do
	echo 'Do you want to save it on:'
	echo '  d - double density diskettes - /dev/rdsk/f0d9dt'
	echo '  q - quad density diskettes - /dev/rdsk/f0q15dt'
	echo '  t - tape - /dev/rmt0'
	echo '  n - no, QUIT'
	echo '> \c'
	read ans
	case $ans in
	  d )   OF=/dev/rdsk/f0d9dt  BS=18 NB=40     DEV=f ; break ;;
	  q )   OF=/dev/rdsk/f0q15dt BS=30 NB=80     DEV=f ; break ;;
	  t )   OF=/dev/rmt0         BS=32 NB=10000  DEV=t ; break ;;
	  n )   exit 0 ;;
	esac
	echo '???'
done

while :
do
	echo 'How many megabytes of memory image do you want to save?'
	echo 'Enter decimal integer or "q" to quit. > \c'
	read ans
	case $ans in
	  q )   exit 0 ;;
	esac
	N=`expr \( $ans \* 2048 + $BS - 1 \) / $BS`
	case $? in
	  0 )   break;;
	esac
	echo '???'
done

SKIP=0
COUNT=$NB

while [ $N -gt 0 ]
do
	if [ $COUNT -gt $N ]
	then
		COUNT=$N
	fi
	echo 'Insert \c'
	case $DEV in
	  f )   echo 'diskette \c' ;;
	  t )   echo 'tape cartridge \c' ;;
	esac
	echo 'and press return, or enter q to quit. > \c'
	read ans
	case $ans in
	  q )   exit 0 ;;
	esac
	echo 'Wait.'
	echo dd if=/dev/swap of=$OF bs=${BS}b count=$COUNT skip=$SKIP
	dd if=/dev/swap of=$OF bs=${BS}b count=$COUNT skip=$SKIP
	N=`expr $N - $COUNT`
	SKIP=`expr $SKIP + $COUNT`
done
echo '\n\nDone.  Use /etc/ldsysdump to copy dump from tape or diskettes'
echo 'Press return to continue >\c'
read ans
