#!/bin/ksh
#==========================================================
# SCRIPT DE GENERATION COMMANDE MEP MIRRORING SUN
#==========================================================
# Auteur  : Nicolas DIETLIN
# Date    : 10/01/2007
# version : 0.3
# OS      : SUN
# Fichier : MepGenSunHLM-0.2.ksh
#==========================================================

#==========================================================
# Variables
#==========================================================
HOST=$(hostname)
CHM=$(pwd)
FILE=$CHM/mep_hlm_$HOST
LISTDG=$(vxdg list | awk ' (NR >=3)  {print $1}')

#==========================================================
# Fonctions
#==========================================================
function ctrlFile {
        if [ -f $FILE ]
        then
                rm $FILE
        fi
}

#==========================================================
# Corps du script
#==========================================================

ctrlFile

echo "5. MEP DE MIRRORING HLM SUN pour $HOST\n=======================================\n" >> $FILE
echo "5.1.1 Rafraichir Veritas Volume Manager\n=======================================" >> $FILE
echo "vxdctl enable\n" >> $FILE

echo "5.1.2 Insertion des nouveaux disques dans les disk groups\n=========================================================\n" >> $FILE
for dg in $LISTDG
do
        echo "./TBX_Insert_disk -d $dg" >> $FILE
done
for dg in $LISTDG
do
        echo "cat ${dg}_ADD_DISK.ksh" >> $FILE
done
echo "\nchmod +x *.ksh" >> $FILE
for dg in $LISTDG
do
        echo "./${dg}_ADD_DISK.ksh" >> $FILE
done

echo "\n5.1.3 Sauvegarde de la configuration logique des disques\n========================================================\n" >> $FILE
for dg in $LISTDG
do
        echo "vxprint -g ${dg} -ht | grep ^dm | grep NEW | wc -l" >> $FILE
        echo "vxprint -g ${dg} -ht | grep ^dm | grep -v NEW | wc -l" >> $FILE
done

echo "5.1.3b Controle de la longueur des plexes sources\n===========================================\n" >> $FILE
echo "chmod +x check_name.ksh" >> $FILE
for dg in $LISTDG
do
	echo "./check_name.ksh ${dg}" >> $FILE
done

for dg in $LISTDG
do
        echo "vxprint -g ${dg} -hQqm > vxprint.hQqm.${dg}" >> $FILE
        echo "vxprint -g ${dg} -ht > vxprint.ht.${dg}" >> $FILE
done

echo "\n5.1.4. generation des scripts suivants\n----------------------------------" >> $FILE
for dg in $LISTDG
do
        echo "./TBX_Build_NEWPLEX -d ${dg} -i" >> $FILE
done

echo "\na. creation des sd\n------------------" >> $FILE
for dg in $LISTDG
do
        echo "./${dg}_create_sd.ksh" >> $FILE
done

echo "\nb. Creation des plexes cibles\n================================" >> $FILE
for dg in $LISTDG
do
        echo "./${dg}_create_plexes.ksh" >> $FILE
done

echo "\n5.1.5 Definition du prefered plexe pour la lecture\n==================================================\n" >> $FILE
echo "chmod +x TBX_PreferPlex\n" >> $FILE
for dg in $LISTDG
do
        echo "./TBX_PreferPlex -d ${dg}"  >> $FILE
        echo "chmod +x ${dg}_PREF_PLEX.ksh" >> $FILE
        echo "./${dg}_PREF_PLEX.ksh\n" >> $FILE
done

echo "5.2 Migration des donnees\n=========================" >> $FILE
echo "\n5.2.1 Migration en mode sequentielle\n------------------------------------" >> $FILE
for dg in $LISTDG
do
        echo "chmod +x ${dg}_mover_SEQ.sh" >> $FILE
        echo "nohup ./${dg}_mover_SEQ.sh 1>${dg}.log 2>&1 &\n" >> $FILE
done

echo "5.2.2 Migration en mode total\n-----------------------------" >> $FILE
for dg in $LISTDG
do
        echo "chmod +x ${dg}_mover_ALL.sh" >> $FILE
        echo "nohup ./${dg}_mover_ALL.sh 1>${dg}.log 2>&1 &\n" >> $FILE
done

echo "5.2.3 Suivi des operations\n--------------------------\n" >> $FILE
echo "vxtask list" >> $FILE

echo "\n5.2.4 Fichier Log\n-----------------" >> $FILE
for dg in $LISTDG
do
        echo "cat $dg.log | grep Term | grep -v ': 0'" >> $FILE
done

echo "\n5.2.5 Validation Veritas\n------------------------" >> $FILE
for dg in $LISTDG
do
        echo "vxprint -g ${dg} -ht | egrep '^$|^v|^pl|^sd'" >> $FILE
done

echo "\n5.3 Etapes POST-MIGRATION (NETTOYAGE DU MIRROIR)\n--------------------------------------------\n" >> $FILE
for dg in $LISTDG
do
        echo "./TBX_Detach_OldPlex -d ${dg}" >> $FILE
	echo "./TBX_Remove_OldPlex -d ${dg}" >> $FILE
	echo "./TBX_Remove_disk -d ${dg}\n" >> $FILE
done
echo "chmod +x *.ksh\n" >> $FILE
for dg in $LISTDG
do
	echo "./${dg}_detach_plex_HR.ksh" >> $FILE
	echo "./${dg}_remove_old_plex_HR.ksh" >> $FILE
	echo "./${dg}_REMOVE_DISK_HR.ksh\n" >> $FILE
done

for dg in $LISTDG
do
	echo "./rename_vxpl-0.1.ksh ${dg}" >> $FILE
	echo "./rename_vxsd-0.1.ksh ${dg}" >> $FILE
	echo "./rename_vxdisk-0.1.ksh ${dg}\n" >> $FILE
done
exit 0
