DB2歸檔備份實現方式cv_db2arch.sh

fjzcau發表於2015-05-18

  1. #!/bin/sh

  2. i_host=`hostname`

  3. i_log=/cvbak/scripts/cv_db2arch_${i_host}.log
  4. echo " " >> $i_log

  5. if [ $# -lt 3 ]
  6. then
  7.   now_time=`date +"%Y%m%d %H:%M:%S"`
  8.   echo "-->0 $now_time" >> $i_log
  9.   echo "Usage: $0 /db2archlog /db2archlog/cv_db2arch flag=1,2" >> $i_log
  10.   exit 1
  11. fi

  12. i_db2arch=$1
  13. i_cv_arch=$2
  14. i_flag=$3

  15. if [ "$i_flag" = "1" -o "$i_flag" = "2" ]
  16. then
  17.   echo "-->1 flag=$i_flag" >> /dev/null
  18. else
  19.   now_time=`date +"%Y%m%d %H:%M:%S"`
  20.   echo "-->2 $now_time" >> $i_log
  21.   echo "-->2 flag=$i_flag" >> $i_log
  22.   exit 2
  23. fi

  24. if [ -d $i_db2arch -a -d $i_cv_arch ]
  25. then
  26.   echo " " > /dev/null
  27. else
  28.   now_time=`date +"%Y%m%d %H:%M:%S"`
  29.   echo "-->flag=$i_flag" >> $i_log
  30.   echo "-->$now_time" >> $i_log
  31.   echo "-->$i_db2arch not exist OR $i_cv_arch not exist !!" >> $i_log
  32.   exit 3
  33. fi

  34. if [ $i_flag -eq 1 ]
  35. then
  36.   now_time=`date +"%Y%m%d %H:%M:%S"`
  37.   echo "-->flag=$i_flag,mv archive log to $i_cv_arch for cv soft backup to tape!" >> $i_log
  38.   echo "-->$now_time" >> $i_log
  39.   echo "-->db2arch=$i_db2arch" >> $i_log
  40.   echo "-->cv_db2arch=$i_cv_arch" >> $i_log
  41.   find $i_db2arch -name "S*.LOG" -type f -mmin +5 |sort >> $i_log
  42.   echo " " >> $i_log
  43.   find $i_db2arch -name "S*.LOG" -type f -mmin +5 | xargs -i /bin/mv {} $i_cv_arch
  44. elif [ $i_flag -eq 2 ]
  45. then
  46.   now_time=`date +"%Y%m%d %H:%M:%S"`
  47.   echo "-->flag=$i_flag,after backup to tape,rm archive log!" >> $i_log
  48.   echo "-->$now_time" >> $i_log
  49.   echo "-->db2arch=$i_db2arch" >> $i_log
  50.   echo "-->cv_db2arch=$i_cv_arch" >> $i_log
  51.   rm $i_cv_arch/*
  52. fi

  53. exit 0

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22661144/viewspace-1660177/,如需轉載,請註明出處,否則將追究法律責任。

相關文章