jqkyp 发表于 2015-5-29 10:46:51

ORACLE自动备份并且自动FTP到备份机的SHELL脚本(http://doc.linuxpk.com/456.html)

  本次上传的脚本有很多可以改进的地方!这也是本人第一次在网上发帖,SH写的不好的地方
  不要见笑!!!!!!本SH以在SCOOPENSERVER 505(ORACLE 7.3.2)和IBM RS6000 AIX 4.3(ORACLE8.1.6)调试通过!!如果要转载,请加上出处!!!谢谢!!!详细功能见脚本文件SH的批注!!!如果能要加上自动执行的功能请使用crontab配置即可!!!!
  第一个文件:INIT.TXT这是脚本INI初始化文件:
  ##################################################################
  #This is a system ini file :
  #   CopyRight By WangZuXiang 2002
  #               the '#' is ingnor :
  #the format style is xxxx=value
  #
  ##################################################################
  #Oracle cionfig
  
  username=ydyx
  password=ydyx
  con_alias=MISDB
  #the main machine config
  
  myhost_ip=10.232.193.2
  myhost_username=oracle
  myhost_password=oracle
  dump_dir=/u2/oracleback
  #the backup machine config
  
  backhost_ip=10.232.193.5
  backhost_username=oracle
  backhost_password=oracleydyx
  backup_dir=/u2/oracleshaoshanback
  #delete the dump file x days ago?!!!
  
  delete_days=2
  #the Oracle database's back method
  #如果start_tactic=Y 则采用策略备份,否则按每天完全到出
  #如果采用策略备份,则必须给SYSTEM用户的口令
  
  start_tactic=N
  system_password=manager11
  #the recode the system execute's log!
  
  sys_log=/home/oracle/wzx/x.log
  #end
  第二个文件:主程序文件:MY.SH:
  #!/bin/sh
  #############################################################################
  #
  #Get the all ini file config
  #CopyRight By WangZuXiang 2002-2005?
  #版权所有(C) 2002-2005? WangZuXiang .
  #All Rights Reserved.
  #program date 2002-10-22
  #usage: main
  #This script is used to start oracle dump database .
  #It should ONLY be executed as part of the crontabs.
  #function content is:
  #1:自动检查是否能连上Oracle!
  #2:通过初始化文本来解析各种需要的参数!
  #3:自动完全到出ORACLE数据库(每天)!,以后将增加相关的增量备份等!
  #4:自动删除配置文件中规定的前X天的备份文件!
  #5:自动将到出文件打包并转存到其他的备份机器上!
  #6:自动记录程序执行过程中的所有日期信息!
  #if you find some bugs please send it to my mailpost :
  #e-mail:wzxherry@sina.com !
  #new function:增加了对ORACLE数据库备份策略的方法!2002-10-31
  ##############################################################################
  mypwd=`pwd`
  inifile=/home/oracle/wzx/init.txt
  oratab=/etc/oratab
  TEMP=temp.$$
  DUMP_FILE=`date +'%Y%m%d`
  initme ()
  {
  #read from the config file 'ini.txt'
  #oracle config
  USERNAME=`cat ${inifile:-"init.txt"} | grep -i '^username' | awk -F = '{print $2}'`
  PASSWORD=`cat ${inifile:-"init.txt"} | grep -i '^password' | awk -F = '{print $2}'`
  MY_ALIAS=`cat ${inifile:-"init.txt"} | grep -i '^con_alias' | awk -F = '{print $2}'`
  #the main host config
  MYHOST_IP=`cat ${inifile:-"init.txt"} | grep -i '^myhost_ip' | awk -F = '{print $2}'`
  MYHOST_USERNAME=`cat ${inifile:-"init.txt"} | grep -i '^myhost_username' | awk -F = '{print $2}'`
  MYHOST_PASSWORD=`cat ${inifile:-"init.txt"} | grep -i '^myhost_password' | awk -F = '{print $2}'`
  DUMP_DIR=`cat ${inifile:-"init.txt"} | grep -i '^dump_dir' | awk -F = '{print $2}'`
  #the backup host config
  BACKHOST_IP=`cat ${inifile:-"init.txt"} | grep -i '^backhost_ip' | awk -F = '{print $2}'`
  BACKHOST_USERNAME=`cat ${inifile:-"init.txt"} | grep -i '^backhost_username' | awk -F = '{print $2}'`
  BACKHOST_PASSWORD=`cat ${inifile:-"init.txt"} | grep -i '^backhost_password' | awk -F = '{print $2}'`
  BACKUP_DIR=`cat ${inifile:-"init.txt"} | grep -i '^backup_dir' | awk -F = '{print $2}'`
  #the define's delete dump file days!
  DAYS=`cat ${inifile:-"init.txt"} | grep -i '^delete_days' | awk -F = '{print $2}'`
  #to get the system log
  LOGS=`cat ${inifile:-"init.txt"} | grep -i '^sys_log' | awk -F = '{print $2}'`
  TACTIC=`cat ${inifile:-"init.txt"} | grep -i '^start_tactic' | awk -F = '{print $2}'`
  SYSTEMPASS=`cat ${inifile:-"init.txt"} | grep -i '^system_password' | awk -F = '{print $2}'`
  #read the config file end.
  }
  #WHOAMI=`id | awk '/uid=*(oracle)/ {print $1}'`
  #WHOAMI=`id | awk '{print $1}' | sed 's/uid=*(.*).*/1/'`
  WHOAMI=`id | sed 's/uid=*(.*) gid.*/1/'`
  #if test "$WHOAMI" = "" ; then
  if test "$WHOAMI" != "(oracle)" ; then
  echo "
  "
  echo "=============================================================="
  echo "=========you must use oracle user to run this script!========="
  echo "=============================================================="
  echo "
  "
  exit 0
  fi
  #run the init parameter
  test ! -e $inifile && echo "not find the init file:"$inifile"!" && exit 0
  initme
  if [ -z $LOGS ]; then
  echo ""
  fi
  #LOG = ${LOGS:-"x.log"}
  LOGME="tee -a ${LOGS:-"x.log"}"
  if [ -e $LOGS -a -f $LOGS ]; then
  if test ! -w $LOGS; then
  echo ""
  exit
  fi
  fi
  echo "
  " | $LOGME
  echo "-----------------------------------------------------------------" | $LOGME
  echo "" | $LOGME
  #check the parameter value
  if [ -z $USERNAME ]; then
  echo ">" | $LOGME
  exit 2
  fi
  if [ -z $MY_ALIAS ]; then
  echo ">" | $LOGME
  exit 0
  fi
  if [ -z $MYHOST_IP ]; then
  echo ">" | $LOGME
  exit 0
  fi
  if [ -z $MYHOST_USERNAME ]; then
  echo "" | $LOGME
  exit 4
  fi
  if [ -z $MYHOST_PASSWORD ]; then
  echo "" | $LOGME
  exit 5
  fi
  if [ -z $BACKHOST_IP ]; then
  echo ">" | $LOGME
  exit 7
  fi
  if [ -z $BACKHOST_PASSWORD ]; then
  echo ">" | $LOGME
  exit 9
  fi
  #elif [ ! -e $BACKUP_DIR-o ! -d $BACKUP_DIR ]; then
  #echo "" | $LOGME
  #exit 0
  #fi
  #if [ ! -O $BACKUP_DIR ]; then
  #echo ">" | $LOGME
  exit 0
  fi
  ORACLE_SID=`cat $oratab | grep -v "^#" | grep "Y$" | awk -F : '{print $1}' `
  if [ -z $ORACLE_SID ]; then
  echo "" | $LOGME
  exit -1
  fi
  export ORACLE_SID
  ORACLE_HOME=`cat $oratab | grep -v "^#" | grep "Y$" | awk -F : '{print $2}' `
  if [ ! -d $ORACLE_HOME ]; then
  echo "the oracle's home directory "$ORACLE_HOME" is not exist..............!>>" | $LOGME
  exit -1
  fi
  export ORACLE_HOME
  PATH=$PATH:$ORACLE_HOME/bin:/usr/lib:/bin:$HOME/bin:.
  ORACLE_BASE=/u1/app/oracle
  export ORACLE_BASE
  ORACLE_SID=misdb
  export ORACLE_SID
  ORACLE_HOME=$ORACLE_BASE/product/8.1.6
  export ORACLE_HOME
  PATH=$PATH:$ORACLE_HOME/bin
  export PATH
  LIBPATH=$LIBPATH:$ORACLE_HOME/lib
  export LIBPATH
  ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
  export ORA_NLS33
  export PATH
  #############################################
  ## begin to dump the database
  #############################################
  #trying to connect oracle .....
  if [ -e $TEMP ]; then
  rm -f $TEMP
  if [ ! $? -eq 0 ]; then
  echo "" | $LOGME
  exit -1
  fi
  fi
  if [ -x $ORACLE_HOME/bin/tnsping ]; then
  #$ORACLE_HOME/bin/tnsping$MY_ALIAS > $TEMP
  tnsping$MY_ALIAS > $TEMP
  ME=`cat $TEMP | grep "OK" | awk '{print $1}'`
  if [ "$ME" != "OK" ]; then
  echo "" | $LOGME
  rm -f $TEMP
  exit $?
  else
  echo "" | $LOGME
  fi
  fi
  rm -f $TEMP
  if [ -x $ORACLE_HOME/bin/exp ]; then
  #MY_ALIAS
  #cd $ORACLE_HOME/bin
  #if [ ! $? -eq 0 ]; then
  #echo "error
  "
  #exit 0
  #fi
  trap "" 1 2 3 15
  #如果不用策略备份,则采用倒用户的方式,到出!!!!
  #echo $TACTIC
  #
  #if [ "$TACTIC" = "Y"]; then
  #if [ -x $ORACLE_HOME/bin/svrmgrl ]; then
  #svrmgrl
页: [1]
查看完整版本: ORACLE自动备份并且自动FTP到备份机的SHELL脚本(http://doc.linuxpk.com/456.html)