自动化RMAN脚本

#!/bin/bash
  # chkconfig: 345 99 10
  # description: script for the SMS MESSAGE OR Oracle Instance, Listener
  #Choose to run the script by week
  #The script will automatically choose the backup level
  #software make : muxinqing
  time=$(date +%A)
  ora=$(ps -aux | grep ora | grep -v "grep" |  wc -l)



 if [ $time=Monday ]; then
  su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" < run
  {allocate channel orademo type disk;
  backup incremental level 0  as compressed backupset database  format '/home/oracle/db_%s_%p_%t' plus archivelog format  '/home/oracle/arch_%s_%p_%t' delete input;
 crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
  }
  m
  else

 su - oracle -c "rman target / msglog=/home/oracle/bakl1.log"  << m
 run
  {allocate channel orademo type disk;
  backup incremental level 1 cumulative as compressed backupset database format 'e:\db_%s_%p_%t' plus archivelog format  'e:\arch_%s_%p_%t' delete input;
 crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
  }
  m

 fi

 版本二
 
   #!/bin/bash
   # chkconfig: 345 99 10
   # description: script for the SMS MESSAGE OR Oracle Instance, Listener
   #Choose to run the script by week
   #The script will automatically choose the backup level
   #software make : muxinqing
   time=$(date +%A)
   ora=$(ps -aux | grep ora | grep -v "grep" |  wc -l)


   case $time in


   'Monday')


   #cmdfile=/backup/script/backup_0_level
   if [ -n ora ]; then
   su - oracle -c "rman target / msglog=/home/oracle/bakl1.log" < run
   {allocate channel orademo type disk;
   backup incremental level 0  as compressed backupset database  format '/home/oracle/db_%s_%p_%t' plus archivelog format  '/home/oracle/arch_%s_%p_%t' delete input;
   crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
   }
   m
   else
   echo "file not exist"
   fi
   ;;
   'Tuesday')


   if [ -n ora ]; then
   su - oracle -c "rman target / msglog=/home/oracle/bakl1.log"  << m
  run
   {allocate channel orademo type disk;
   backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format  'e:\arch_%s_%p_%t' delete input;
   crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
   }
   m
   else
   echo "file not exist"
   fi
   ;;
   'Wednesday')


   if [ -n ora ]; then
   su - oracle -c "rman target / msglog=/home/oracle/bakl1.log"  << m
   run
   {allocate channel orademo type disk;
   backup incremental level 1 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format  'e:\arch_%s_%p_%t' delete input;
   crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
   }
   m
   else
   echo "file not exist"
   fi
   ;;


   'Thursday')




  if [ -n ora ]; then
   su - oracle -c "rman target / msglog=/home/oracle/bakl1.log"  << m
   run
   {allocate channel orademo type disk;
   backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format  'e:\arch_%s_%p_%t' delete input;
   crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
   }
   m
   else
   echo "file not exist"
   fi
   ;;


   'Friday')


   if [ -n ora ]; then
   su - oracle -c "rman target / msglog=/home/oracle/bakl1.log"  << m
   run
   {allocate channel orademo type disk;
   backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format  'e:\arch_%s_%p_%t' delete input;
   crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
   }
   m
   else
   echo "file not exist"
   fi
   ;;


   'Saturday')
   if [ -n ora ]; then
   su - oracle -c "rman target / msglog=/home/oracle/bakl1.log"  << m
   run
   {allocate channel orademo type disk;
   backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format  'e:\arch_%s_%p_%t' delete input;
   crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
   }
   m
   else
   echo "file not exist"
   fi
   ;;


   'Sunday')


   if [ -n ora ]; then
   su - oracle -c "rman target / msglog=/home/oracle/bakl1.log"  << m
   run
   {allocate channel orademo type disk;
   backup incremental level 2 cumulative as compressed backupset database include current controlfile format 'e:\db_%s_%p_%t' plus archivelog format  'e:\arch_%s_%p_%t' delete input;
   crosscheck backup;
  delete noprompt expired backup;
  Delete noprompt obsolete;
  crosscheck archivelog all;
  delete noprompt expired archivelog all;
  backup current controlfile format '/data1/control%T%U';
   }
   m
   else
   echo "file not exist"


  fi

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29065182/viewspace-1593395/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29065182/viewspace-1593395/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值