Home

Wednesday, March 21, 2012

Script untuk membuat Baseline

Di setiap project kita harus mempunyai BASELINE yang bertujuan sebagai backup untuk semua system yang kita handle dalam suatu project . BASELINE ini biasanya dilakukan setiap kali kita akan melakukan sebuah perubahan yang signifikan dalam sebuah system kita harus melaukuan backup BASELINE untuk keperluan Rollback incase  aktivitas perubahan mengalami kegagalan. BASELINE ini adalah backup yang bersifat consistent  (cold backup) dimana backup seperti ini paling powerfull dan mudah dalam restorisasinya.
Berikut ini contoh BASELINE script untuk untuk applikasi dan database (oracle) yang pernah saya buat di project yang saya handle :


#!/bin/sh
#------------------------------------------------------------------------#
# This script will backup the  database and application files    #
#          #
#------------------------------------------------------------------------#
# Author: Sidnei B & Ida Bagus Enderajana (LCMG) [2006]    #
#------------------------------------------------------------------------#
#
#--------------------------------------------------------------------------------------------#
# Environment for the oracle database             #
#--------------------------------------------------------------------------------------------#
ORACLE_BASE=/u01/app/oracle;      export ORACLE_BASE      #
ORACLE_HOME=$ORACLE_BASE/product/9.2.0;    export ORACLE_HOME      #
ORACLE_SID=DBNAme;       export ORACLE_SID      #
ORACLE_OWNER=oracle;       export ORACLE_OWNER      #
ORACLE_TERM=vt220;       export ORACLE_TERM      #
PATH=$PATH:$ORACLE_HOME/bin:/usr/bin:/opt/bin:/usr/ccs/bin;  export PATH       #
LD_LIBRARY_PATH=$ORACLE_HOME/lib:     export LD_LIBRARY_PATH      #
#--------------------------------------------------------------------------------------------#
#------------------------------------------------#
# Append this to the end of the baseline number  #
#------------------------------------------------#
BASELINE_NUM=$1   # the front name for the current baseline being taken
BASELINE_DIR=$2   # directory that the files will be stored into
BASELINE_DATE=`date | sed -e "s/:/_/g" | sed -e "s/ /_/g"`
#----------------------------#
# TEST for the entry name    #
#----------------------------#
if [ "$BASELINE_NUM" = "" ];then
 echo "missing the baseline name ....."
        echo "usage:<$0 <baseline_(number)> <backup dir> example:baseline_eventlink.sh baseline_4 /backup"
        exit 1
fi
#--------------------------------------#
# TEST for the backup directory entry  #
#--------------------------------------#
if [ "$BASELINE_DIR" = "" ];then
 echo "missing the backup directory name ....."
        echo "usage:<$0 <baseline_(number)> <backup dir> example:baseline_eventlink.sh baseline_4 /backup"
        exit 1
fi
BASELINE_FNAME="EL_${BASELINE_NUM}_${BASELINE_DATE}"
COMPLETE_BASE_PATH=$BASELINE_DIR/$BASELINE_FNAME
if [ ! -d $COMPLETE_BASE_PATH ];then
 mkdir $COMPLETE_BASE_PATH
fi
#-------------------------------------------------#
# Decide on the TNS                               #
#-------------------------------------------------#
HOSTNAME=`hostname`
HOST_TYPE=`echo "$HOSTNAME" | grep "nelp"`
if [ "$HOST_TYPE" = "" ];then
 #-- Means its the test server  --#
 TNS_TYPE="DBTEST1"
else
 # Means its the production server #
 TNS_TYPE="DBPROD"
fi
echo "#-----------------------------------------------#"
echo "# WELCOME TO THE EVENTLINK BASELINE SCRIPT      #"
echo "#-----------------------------------------------#"
echo "# The script will be baselineing the following  #"
echo "# *- Database files          #"
echo "# *- Log files           #"
echo "# *- Control files          #"
echo "# *- Application Files          #"
echo "#-----------------------------------------------#"

#----------------------------------------------------#
# These are the directories that we need to baseline #
#----------------------------------------------------#
echo "## ... creating a baseline apps file with name $BASELINE_FNAME_APPS.tar"
tar -cvf ${COMPLETE_BASE_PATH}/${BASELINE_FNAME}_APPS.tar /data2/eventlink/data/node_packages
#----------------------------------------------------------#
# These are the database files that we need to baseline    #
#----------------------------------------------------------#
DATA_DBF=`echo "select file_name from dba_data_files;" | sqlplus baseline/baseline@$TNS_TYPE | grep -i dbf `
DATA_LOG=`echo "select member from v\\$logfile;"       | sqlplus baseline/baseline@$TNS_TYPE | grep -i log `
DATA_CTR=`echo "select name from v\\$controlfile;"     | sqlplus baseline/baseline@$TNS_TYPE | grep -i ctl `
#------------------------------------------------#
# Shutting down the database server              #
#------------------------------------------------#
#
LOOP=1
 while [ 1 ]
 do
  clear
  echo "#-------------------------------------------------#"
   echo "# Would you like to shutdown the databasae server #"
  echo "#-------------------------------------------------#"
  echo "# -* ENTER Y for yes                              #"
  echo "# -* ENTER N for no                               #"
  echo "#-------------------------------------------------#"
  echo ">>>>: "
  read   OPT
  if [ "$OPT" = "Y" ];then
   echo "We are shuting down the database server..."
   sleep 10
   #------------------------------------
   # Dont do this just yet
   # $ORACLE_HOME/bin/dbshut
   # $ORACLE_HOME/bin/lsnrctl stop
   #------------------------------------
   break
  fi
  if [ "$OPT" = "N" ];then
   echo "Database server not being shutdown ... exiting script ..."
   exit 0
  else
   echo "INVALID OPTION PLEASE CHOOSE AGAIN"
  fi
 done
#---------------------------------------------------------------#
# Loop through all the of the database files that have been     #
# found from the sql commands and add them into the tar file    #
#---------------------------------------------------------------#
FLAG=0
for ORACLE_FILES in `echo "$DATA_DBF $DATA_LOG $DATA_CTR"`
do
        if [ $FLAG -eq 0 ];then
  echo "----------------------------------------------------------------------"
  echo " creating file EL_ORACLE_BACKUP_`hostname`.tar adding + $ORACLE_FILES "
  echo "----------------------------------------------------------------------"
                tar -cvf  ${COMPLETE_BASE_PATH}/EL_ORACLE_BACKUP_`hostname`.tar $ORACLE_FILES
                FLAG=1
        else
  echo "----------------------------------------------------------------------"
  echo " creating file EL_ORACLE_BACKUP_`hostname`.tar append + $ORACLE_FILES "
  echo "----------------------------------------------------------------------"
                tar -rvf  ${COMPLETE_BASE_PATH}/EL_ORACLE_BACKUP_`hostname`.tar $ORACLE_FILES
        fi
done
echo "-------------------------------------------------"
echo " BASELINE for EL HOST `hostname` ended at `date` "
echo "-------------------------------------------------"
#-----------------#
# End script   #
#-----------------#
exit 0

No comments:

Post a Comment