Sybase 数据库启停脚本
前言:上周五去机房给客户部署Sybase ASE双机热备,最后在SUSE HA测试过程中,启停脚本出现一些问题,后来经过修改,问题解决。那天晚上在机房待到23:50分左右才离开,到家已经是凌晨1点多了,总结原因还是自己经验不足,准备不充分。下面把在本地测试相关脚本贴出来,供参考:
SYBASE:/home/huyong/sybase/scripts # vi sybase.sh
#!/bin/bash

statusSYBASE(){
      su - huyong -c "/home/huyong/sybase/ASE-15_0/install/showserver" |grep /home/huyong/sybase/ASE-15_0/bin/dataserver 1>/dev/null 2>&1
if [ $? -eq 0 ] ; then
      return 0
else
      return 1
fi
}

startSYBASE(){
      su - huyong -c "/home/huyong/sybase/ASE-15_0/install/startserver -f /home/huyong/sybase/ASE-15_0/install/RUN_hbang" 1>/dev/null 2>&1
      su - huyong -c "/home/huyong/sybase/ASE-15_0/install/startserver -f /home/huyong/sybase/ASE-15_0/install/RUN_hbang_BS" 1>/dev/null 2>&1
declare -i startRETRY=0
while [ $startRETRY -lt 30 ] ; do
statusSYBASE
if [ $? -eq 0 ] ; then
      su - huyong -c "/home/huyong/sybase/ASE-15_0/install/startserver -f /home/huyong/sybase/ASE-15_0/install/RUN_hbang" 1>/dev/null 2>&1
      su - huyong -c "/home/huyong/sybase/ASE-15_0/install/startserver -f /home/huyong/sybase/ASE-15_0/install/RUN_hbang_BS" 1>/dev/null 2>&1   
      return 0
fi
      sleep 1
      startRETRY=`expr $startRETRY + 1`
      done
      return 1
}

stopSYBASE(){
      /home/huyong/sybase/ASE-15_0/install/showserver|grep /home/huyong/sybase/ASE-15_0/bin/dataserver >/dev/null 2>&1
      /home/huyong/sybase/ASE-15_0/install/showserver|grep /home/huyong/sybase/ASE-15_0/bin/backupserver >/dev/null 2>&1
declare -i stopRETRY=0
while [ $stopRETRY -lt 30 ] ; do
      su - huyong -c "isql -Usa -Phbang123 -Shbang  <<-EOF
use master
go
checkpoint
go
shutdown SYB_BACKUP 
go
shutdown with nowait
go
exit
EOF" 1>/dev/null 2>&1
      su - huyong -c "kill -9 `/home/huyong/sybase/ASE-15_0/install/showserver|grep /home/huyong/sybase/ASE-15_0/bin/dataserver |awk '{print $4}'`"  1>/dev/null 2>&1
      su - huyong -c "kill -9 `/home/huyong/sybase/ASE-15_0/install/showserver|grep /home/huyong/sybase/ASE-15_0/bin/backupserver |awk '{print $4}'`" 1>/dev/null 2>&1
statusSYBASE
if [ $? -ne 0 ] ; then
      return 0
fi
      sleep 1
      stopRETRY=`expr $stopRETRY + 1`
      done
      return 1
}

if [ $# -ne 1 ] ; then
      echo "Usage $0 {start|stop|status}"
      exit 123
fi
case $1 in
start)
startSYBASE
if [ $? -eq 0 ] ; then
      echo "Start hbang Sybase succeed."
      exit 0
else
      echo "Start hbang Sybase failed!"
      exit 1
fi
;;
stop)
statusSYBASE
if [ $? -ne 0 ] ; then
      echo "hbang Sybase have been sopped."
      exit 0
fi
stopSYBASE
if [ $? -eq 0 ] ; then
      echo "Stop hbang Sybase succeed."
      exit 0
else
      echo "Stop hbang Sybase failed!"
      exit 1
fi
;;
status)
statusSYBASE
if [ $? -eq 0 ] ; then
      echo "hbang Sybase is running..."
      exit 0
else
      echo "hbang Sybase is dead!"
      exit 1
fi
;;
*)
      echo "Usage: $0 {start|stop|status}"
exit 123
;;
esac
测试过程如下:
--正常情况

SYBASE:/home/huyong/sybase/scripts # ./sybase.sh status ;echo $?
SYBASE Sybase is dead!
1
SYBASE:/home/huyong/sybase/scripts # ./sybase.sh start ;echo $?
Start SYBASE Sybase succeed.
0

SYBASE:/home/huyong/sybase/scripts # ps -ef|grep hbang
huyong    5538     1  0 11:04 ?        00:00:00 /bin/sh /home/huyong/sybase/ASE-15_0/install/RUN_hbang
huyong    5540  5538 80 11:04 ?        00:00:20 /home/huyong/sybase/ASE-15_0/bin/dataserver -d/home/huyong/sybase/data/master.dat -e/home/huyong/sybase/ASE-15_0/install/hbang.log -c/home/huyong/sybase/ASE-15_0/hbang.cfg -M/home/huyong/sybase/ASE-15_0 -shbang
huyong    5567     1  0 11:04 ?        00:00:00 /bin/sh /home/huyong/sybase/ASE-15_0/install/RUN_hbang_BS
huyong    5570  5567  0 11:04 ?        00:00:00 /home/huyong/sybase/ASE-15_0/bin/backupserver -e/home/huyong/sybase/ASE-15_0/install/hbang_BS.log -N25 -C20 -M/home/huyong/sybase/ASE-15_0/bin/sybmultbuf -Shbang_BS
root      5694  2426  0 11:04 pts/1    00:00:00 grep hbang
SYBASE:/home/huyong/sybase/scripts #

SYBASE:/home/huyong/sybase/scripts # ./sybase.sh stop ;echo $?
Stop SYBASE Sybase succeed.
0
SYBASE:/home/huyong/sybase/scripts # ./sybase.sh status ;echo $?
SYBASE Sybase is dead!
1
SYBASE:/home/huyong/sybase/scripts # ps -ef|grep hbang
root      6002  2426  0 11:05 pts/1    00:00:00 grep hbang
SYBASE:/home/huyong/sybase/scripts #

--异常情况
huyong@SYBASE:~/sybase> pwd    
/home/huyong/sybase
huyong@SYBASE:~/sybase> mv data/ data.dat   --启动之前模拟数据文件丢失

SYBASE:/home/huyong/sybase/scripts # ./sybase.sh status ;echo $?
hbang Sybase is dead!
1
SYBASE:/home/huyong/sybase/scripts # ./sybase.sh start ;echo $?
Start hbang Sybase failed!
1

-------END-------------