#!/bin/bash
# ************************************************************
# *
# * Name: RESTSNAPVOL
# *
# * Desc: Restore a single volume from a snapshot
# *
# ************************************************************
PATH=../hercules:${PATH}
THISDIR=`pwd`
cd ..
GENDIR=`pwd`
cd ${THISDIR}

if [ "$#" = "0" ]
then
   clear
   echo "* Two call parameters are required!"
   echo "*"
   echo "* USAGE: $0 [snapshot] [volume]"
   echo "*        $0 !          !"
   echo "*        $0 !          +--- volume of disk to restore"
   echo "*        $0 +-------------- snapshot number"
   echo " "
   exit
elif [ "$#" = "1" ]
then
   clear
   echo "* You have forgotten one parameter!"
   echo "*"
   echo "* USAGE: $0 [snapshot] [volume]"
   echo "*        $0 !          !"
   echo "*        $0 !          +--- volume of disk to restore"
   echo "*        $0 +-------------- snapshot number"
   echo " "
   exit
fi
if [ "${2}" = "mvsres" ]
then
   VOL="mvsres.148"
elif [ "${2}" = "mvsdlb" ]
then
   VOL="mvsdlb.248"
elif [ "${2}" = "start1" ]
then
   VOL="start1.150"
elif [ "${2}" = "spool0" ]
then
   VOL="spool0.151"
elif [ "${2}" = "pub000" ]
then
   VOL="pub000.240"
elif [ "${2}" = "pub001" ]
then
   VOL="pub001.241"
else
   echo "The volume name" ${2} "is invalid"
   exit
fi

if ! test -f ../snapshot/snap${1}_${2}.tgz
then
   clear
   echo "* You have are trying to restore from snap"${1}"_"${2}".tgz"
   echo "* This file does not exist in the snapshot directory"
   echo "* Are you sure you have specified the correct snapshot number?"
   echo "*"
   echo "* USAGE: $0 [snapshot] [volume]"
   echo "*        $0 !          !"
   echo "*        $0 !          +--- volume of disk to restore"
   echo "*        $0 +-------------- snapshot number"
   echo "*"
   echo "* Press the ENTER key to continue"
   read dummy
   exit
fi
tar -Pxzvf ../snapshot/snap${1}_${2}.tgz ../dasd/${VOL}
