#!/sbin/ksh

# Make sure the DIF backup directory exists
if [ ! -d /twc/dif_backup ]
then
	mkdir /twc/dif_backup
fi



# Find the name of the data file (if it is larger than 1Meg)
#OLD_WAY DIF_FILE=`find /twc/dif -name wxl_dif.dat -size +1000000c -prune -print`
#OLD_WAY BKUP_FILE=`find /twc/dif_backup -name wxl_dif.dat -size +1000000c -prune -print`
DIF_FILE=`find /twc/dif/wxl_dif.dat -size +1000000c -prune -print`
BKUP_FILE=`find /twc/dif_backup/wxl_dif.dat -size +1000000c -prune -print`



# If we found a dif data file which looks large enough to be valid
if [ ${DIF_FILE}x = /twc/dif/wxl_dif.datx ]
then
	# Back it up in case we need to restore it later.
	cp /twc/dif/wxl_dif* /twc/dif_backup
else
	# If we have a backup copy which is large enough to be valid
	if [ ${BKUP_FILE}x = /twc/dif_backup/wxl_dif.datx ]
	then
		# Make a record of the files before restoring the backup
		date >> /twc/log/check_dif.log
		ls -al /twc/dif/wxl_dif* /twc/dif_backup/wxl_dif* >> /twc/log/check_dif.log
		echo "RESTORING DIF BACKUP" >> /twc/log/check_dif.log

		# Restore the entire directory
		cp /twc/dif_backup/wxl_dif* /twc/dif
	fi
fi

