Linux에서 전체 RMAN 증분 백업 셸 스크립트

13136 단어 셸 스크립트
이 백업 스크립트는 네트워크에서 정리되었고, 주석만 추가되었습니다.이 스크립트는 사고방식이 뚜렷하여 조금만 바꾸면 생산기에 응용할 수 있다.
  1 #!/bin/bash

  2 #######################################################################

  3 #

  4 #        :

  5 #          0   ,

  6 #       ,      ,

  7 #       , , ,      ,

  8 #    00 4 * * 0 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 0

  9 #    00 4 * * 1,4 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 1

 10 #    00 4 * * 2,3,5,6 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 2

 11 #

 12 #######################################################################

 13 #    :

 14 #set env

 15 #               

 16 export ORACLE_BASE=/u01/app/oracle

 17 export ORACLE_HOME=$ORACLE_BASE/db10g

 18 export ORACLE_SID=emar

 19 export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

 20 export PATH=$ORACLE_HOME/bin:$PATH

 21 

 22 DATE=`date +%w`

 23 DATE_2=`date +%Y%m%d`

 24 BACKUP_PATH=/u01/app/oracle/rman_bak

 25 #      :    

 26 LEVEL=$@

 27 TARGET_SID=emar

 28 RMAN_SID=emar.emar

 29 BIN=/u01/app/oracle/db10g/bin

 30 

 31 # Delete the data backuped last time                

 32 #rm -rf $BACKUP_PATH/data/$DATE/*

 33 

 34 if [ $# != 1 ]; then

 35         echo "usage: rman_bak.sh n

 36         where n is the rman backup level(0,1,2 is permitted)."

 37         exit 1

 38 fi

 39 

 40 if [ $@ -ne 0 -a $@ -ne 1 -a $@ -ne 2 ]; then

 41         echo "usage: rman_bak.sh n

 42         where n is the rman backup level(Only 0,1,2 is permitted)."

 43         exit 2

 44 fi

 45 

 46 echo "-----------------------------start-----------------------------";date

 47 

 48 #0   ,  rman    here document

 49 if [ $LEVEL = 0 ]; then

 50 

 51         $BIN/rman log $BACKUP_PATH/log/level.$TARGET_SID.$LEVEL.$DATE_2.log <<EOF  

 52         connect target sys/sys202;

 53         #  catalog

 54         connect catalog rman/rman@$RMAN_SID;

 55         resync catalog;

 56         run{

 57                 allocate channel c1 type disk ;

 58                 #             

 59                 crosscheck backupset of archivelog all ;

 60                 #  7        ;format            

 61                 backup filesperset 3 format '$BACKUP_PATH/data/$DATE/arch.%d.live.$LEVEL.%t'(archivelog from time 'sysdate-7' all delete input) ;

 62                 #     expired     ,noprompt    

 63                 delete noprompt expired backupset of archivelog all ;

 64                 release channel c1 ;

 65         }

 66 

 67         run{

 68                 allocate channel c2 type disk ;

 69                 crosscheck backupset of database ;

 70                 backup incremental level $LEVEL filesperset 3 format '$BACKUP_PATH/data/$DATE/data.%d.live.$LEVEL.%t'(database include current controlfile) ;

 71                 --sql 'alter system archive log current';

 72                 delete noprompt expired backupset of database ;

 73                 delete noprompt obsolete ;

 74                 release channel c2 ;

 75         }

 76         exit;

 77 EOF

 78 

 79 #              1,2   

 80 else

 81         $BIN/rman log $BACKUP_PATH/log/level.$TARGET_SID.$LEVEL.$DATE_2.log <<EOF  

 82         connect target sys/sys202;

 83         connect catalog rman/rman@$RMAN_SID;

 84         resync catalog;

 85         run{

 86                 allocate channel c1 type disk ;

 87                 --sql 'alter system archive log current';

 88                 crosscheck backupset of archivelog all ;

 89                 backup filesperset 3 format '$BACKUP_PATH/data/$DATE/arch.%d.live.$LEVEL.%t' (archivelog from time 'sysdate-1' all) ;

 90                 delete noprompt expired backupset of archivelog all ;

 91                 release channel c1 ;

 92         }

 93 

 94         run{

 95                 allocate channel c2 type disk ;

 96                 crosscheck backupset of database ;

 97                 backup incremental level $LEVEL filesperset 3 format '$BACKUP_PATH/data/$DATE/data.%d.live.$LEVEL.%t' (database include current controlfile) ;

 98                 --sql 'alter system archive log current';

 99                 delete noprompt expired backupset of database ;

100                 delete noprompt obsolete ;

101                 release channel c2 ;

102         }

103 

104         exit;

105 EOF

106 fi

107 

108 $BIN/exp rman/rman@$RMAN_SID file=$BACKUP_PATH/data/$DATE/live.rman.$DATE_2.dmp log=$BACKUP_PATH/log/$RMAN_SID.rman.$DATE_2.log

109 

110 echo "------------------------------end------------------------------";date

좋은 웹페이지 즐겨찾기