自動化RMAN指令碼

muxinqing發表於2015-04-23

#!/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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章