User Tools

Site Tools


aix:script_mirrorpool
[root@nim]/root/scripts/bin# cat check_mirrorpool.sh
#!/bin/ksh93
#@(#) List Mirror pool compliance
# This script will only display if something is wrong, NOK
# detail output in log file
# Mirrorpool allows mirroring by site, on multiple disk to be sure that each site 
# has a complete copy of data, and that each PP copy is located is located on one site
# generate also as cmd file with commands to relocate to be compliant (migratelp)
# v1.0 11-2016

dir=$(dirname $0)
. $dir/.env

EXCLUDE_VG="testvg"
# $configfile will contain a variable: EXCLUDE_VG which is a list of VG in egrep format
[[ -e "$configfile" ]] && { . $configfile; }

logfile=$logpath/check_mirrorpool.out

cur_date=$(date '+%d-%m-%Y %H:%M')
debug=no

#------------------------------------------------
#*****************************************************
# dmsg ()
#
# Display message
#*****************************************************
dmsg()
{
if [ $debug == "yes" ]
then
   echo "$1"
fi
}

#------------------------------------------------
#*****************************************************
# usage ()
#
# Display message
#*****************************************************
usage()
{
echo "Usage: "$0
echo "\tNo parameter required"
echo "\tCheck mirroring consistency, and mirrorpool strictness"
echo "\tWill create a command file to relocate LPs in case of bad copies on mirrorpool"
exit 1
}

#------------------------------------------------
#*****************************************************
# list pv and mp ()
#
# List PV and associated Mirror Pools
#*****************************************************
list_pv_mp()
{
cat /dev/null > $logfile.pv
for i in $(lspv | grep -v None | awk '{print $1","$2","$3","$4}')
do
  if [[ $(echo $i | cut -d',' -f4) != "" ]]
  then
    pv=$(echo $i | cut -d',' -f1)
    echo "$pv $(lspv $pv | grep POOL | awk '{print $3}')" >> $logfile.pv
  fi
done

list_vg_scal=""   # list scalable VG that supports MIRRORPOOL
list_vg_std=""    # list big and standard VG
for vg in $(lsvg -o | grep -v "caavg_private" | egrep -v "${EXCLUDE_VG}")
do
  lsvg $vg | grep POOL > /dev/null 2>&1
  if [ $? -eq 0 ]
  then
    # force to check even if VG not in strictness mode
    if [ $(lsvg -P $vg | grep -v '^Physical' | awk '{print $2}' | sort -u | wc -l | awk '{print $1}') -gt 1 ]
    then
      # Mirror pool defined on the VG then we can check strictness
      echo "###### VG: $vg scalable"
      list_vg_scal=$(echo $list_vg_scal" "$vg)
    else
      echo "###### VG: $vg standard"
      list_vg_std=$(echo $list_vg_std" "$vg)
    fi
  else
    # Big or normal VG whithout mirror pool
    echo "###### VG: $vg standard"
    list_vg_std=$(echo $list_vg_std" "$vg)
  fi
done
}

#------------------------------------------------
#*****************************************************
# check consistency on Mirror Pools ()
#
# List PV and associated Mirror Pools
#*****************************************************
check_mirror_pool()
{
cat /dev/null > $logfile
for vgs in ${list_vg_scal}
do
  OKvg="OK"
  lsvg -l $vgs | grep jfs | awk '{print $1}' | while read lv
  do
    OKlv="OK"
    i=1
    lslv $lv | grep POOL | grep -v None | cut -d':' -f2 | awk '{print $1}' | while read mp
    do
      lv[$i]=$mp
      let i="($i +1)"
    done

    lslv -m $lv | awk '{print $1";"$2";"$3";"$4";"$5";"$6";"$7}' | grep -v "PP1" | grep -v "$lv:" > $logfile.map

    cat $logfile.map > $logfile.1

    for pv in $(lsvg -p $vgs | grep hdisk | awk '{print $1}')
    do
      mp_pv=$(grep "$pv " $logfile.pv | awk '{print $2}')
      cat $logfile.1 | sed "s/;${pv};/;${mp_pv};/g" > $logfile
      cat $logfile > $logfile.1
    done

    cat $logfile | while read line
    do
      mp1=$(echo $line | awk -F';' '{print $3}')
      mp2=$(echo $line | awk -F';' '{print $5}')
      lp_nb=$(echo $line | awk -F';' '{print $1}' | sed 's/^0*//g')
      first=$(echo $line | awk -F';' '{print $1}')
      word=$(grep "^$first;" $logfile.map)
      if [[ "$mp1" != "${lv[1]}" ]]
      then
        OKlv="Nok"
        OKvg="Nok"
        dmsg $word
        hd2=$(echo $word | awk -F';' '{print $5}')
        echo "migratelp $lv/$lp_nb/1 $hd2" >> $logfile.cmd
      fi
      if [[ "$mp2" != "${lv[2]}" ]]
      then
        OKlv="Nok"
        OKvg="Nok"
        dmsg $word
        hd1=$(echo $word | awk -F';' '{print $3}')
        echo "migratelp $lv/$lp_nb/2 $hd1" >> $logfile.cmd
      fi
    done
    echo "LV:$lv $OKlv"
  done
  strictness=$(lsvg $vgs | grep "MIRROR POOL STRICT" | cut -d':' -f2 | awk '{print $1}')
  echo "VG:$vgs MIRRORPOOL: $strictness STATUS: $OKvg"
  if [ "$OKvg" == "Nok" ]
  then
    echo "Mirroring error on host $(hostname -s) $vgs MirrorPool strictness on LV Nok" >> $logname
    echo "Relocalize the wrong PP on disks with script $logfile.cmd"
  fi
done
}

#------------------------------------------------
check_mirror_disks()
{
cat /dev/null > $logfile
for vgs in ${list_vg_std}
do
  OKvg="OK"
  copies=$(lsvg -l $vgs | awk '{print $1,$2,$3,$4}' | egrep "jfs|boot|paging" | while read a i j k
do
  echo "scale=0;$k/$j" | bc
done | sort -u)
  if [ $(echo $copies | tr ' ' '\n' | wc -l) -gt 1 ]
  then
    OKvg=Nok
    echo "Mirror copies are not correct on host $(hostname -s) $vgs Nok" >> $logname
  else
    if [ "$copies" -gt 1 ]
    then
      for pvs in $(lsvg -p $vgs | grep -v '^PV_NAME' | grep -v "$vgs" | awk '{print $1}')
      do
        if [ $(lspv -M $pvs | awk '{print $2}' | cut -d':' -f3 | sed '/^$/d' | rev | sort -u | wc -l | awk '{print $1}') -gt 1 ]
        then
          echo "PV:$pvs Nok"
          OKvg="Nok"
          echo "Mirroring error on host $(hostname -s) $vgs $pvs has wrong LV copies" >> $logname
        else
          echo "PV:$pvs OK"
        fi
      done
    fi
  fi
  if [ $(lsvg $vgs | grep STALE | rev | cut -d' ' -f1) != "0" ]
  then
    echo "VG:$vgs STATUS: Nok"
  else
    echo "VG:$vgs STATUS: $OKvg"
  fi
done

rm $logfile.pv $logfile.1 $logfile > /dev/null 2>&1
}

#*****************************************************
# Main ()
#*****************************************************
date > $logname
main ()
{
while [ $# -gt 0 ]
do
   case "$1" in
      -v) debug=yes;;
      -h) usage;;
   esac
   shift
done

cat /dev/null > $logfile.cmd

list_pv_mp
check_mirror_pool
check_mirror_disks

chmod 400 $logfile.cmd
}

main | tee -a $logname
aix/script_mirrorpool.txt · Last modified: 2021/01/01 21:21 (external edit)