#/bin/sh
#created by hewd 2002-11-26

ReleaseDir=~www
ParamDir=paramFile
OmcDir=/usr/local/omc
BssVersion=iw05_01.050
srcDataDir=/usr/local/mysql/data
dstDataDir=data

###############################################################################
#Check the user must be root
###############################################################################

if [ `whoami` != "root" ] ; then
	echo "Error:"
	echo " Just root user can execute this program! "
	echo " "
	exit
fi

####################################################
echo "=======Backuping bss's cfg files======"
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do
	bssId="bss-"$i
	ip4="`expr 100 + $i`"
	bssIp=172.18.128.$ip4
	isConnect=`ping -c 1 -i 1 -w 1 $bssIp 2>>/dev/null |grep -c time`
	if [ $isConnect -gt 0 ] ; then
		echo "$bssId connected"
		cd /home/build/${BssVersion}/compile
		mkdir -p cfgBak/$bssId
		cd cfgBak/$bssId
		rm -rf *
		../../hdget $bssIp $BssVersion/compile/cfg
		echo "========Backup $bssId's cfg file finished======="
	else
		echo "$bssId cannot connect"
	fi
done
chown -R build:omc /home/build

cd $ReleaseDir
mkdir -p $ParamDir
cd $ParamDir
rm -rf * 

cp -rf /home/build/iw05_01.050/compile/cfgBak ./


#stop process
omcd stop
mysqld stop

#copy Import program
cp -f /usr/local/omc/tools/paramImport ./
chmod 755 paramImport

####################################################
echo "=======Backuping omc's conf files======"
cp -rf $OmcDir/bin/conf ./

####################################################
echo "=======Backuping omc's database files======"

mkdir -p $dstDataDir

needCopyDirList="AUC_DB BssOmcDb CDR_DB CSTA_DB EIR_DB HLR_DB \
			OBJ_* OMC_PUB PPS_DB SN_DB VLR_DB VMS_DB mysql"

for tmpDir in $needCopyDirList ; do
	cp -rf $srcDataDir/$tmpDir $dstDataDir
	echo "cp -rf $srcDataDir/$tmpDir $dstDataDir"
done 

####################################################
echo "=======Packeting all config files======"
cd $ReleaseDir
dateStr=`date +%Y-%m-%d`
hostName=`hostname -s`
tar zvcf param_${hostName}_${dateStr}.tgz ./$ParamDir
rm -rf ./$ParamDir

echo "========Export Parameter File Finished========"
#start process
mysqld start
omcd start

exit
