1. 程式人生 > >RMAN For 11gR2 RAC指令碼備份

RMAN For 11gR2 RAC指令碼備份

1.建立指令碼,備份集,備份日誌存放路徑


mkdir /data/scripts -p                  //備份指令碼路徑
mkdir /data/rman_bak/data -p  //備份集存放路徑
mkdir /data/rman_bak/logs -p  //備份日誌存放路徑


chown oracle:oinstall /data -R  //設定路徑屬主
chmod 777 /data -R                    //設定路徑許可權


2.指令碼內容如下
/data/scripts/rman_bak.sh  //根據具體環境修改指令碼自定義備份策略,該指令碼設定的備份策略為保留2個副本,所需空間為3+增量備份空間容量,歸檔日誌為刪除7天前歸檔日誌。


##############################################################################
#!/bin/bash  
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=orcl1
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export PATH=$ORACLE_HOME/bin:$PATH
[email protected]

DATE=`date +%w`
DATE_2=`date +%Y%m%d`
BACKUP_PATH="/data/rman_bak"
BIN=$ORACLE_HOME/bin


if [ $# != 1 ]; then
echo "usage: rman_bak.sh n    
where n is the rman backup level(Only 0,1 is permitted)."    
exit 1
fi


if [ [email protected] -ne 0 -a [email protected] -ne 1 ]; then
echo "usage: rman_bak.sh n    
where n is the rman backup level(Only 0,1 is permitted)."    
exit 2
fi


if [[ $LEVEL = 0 ]]; then
$BIN/rman log $BACKUP_PATH/logs/level.$ORACLE_SID.$LEVEL.$DATE_2.log <<EOF


connect target /;  
CONFIGURE RETENTION POLICY TO REDUNDANCY 3;
run{    
allocate channel c1 device type disk connect  'sys/
[email protected]
';    
#allocate channel c2 device type disk connect  'sys/[email protected]';    
crosscheck backupset of archivelog all;    
backup archivelog  all format '$BACKUP_PATH/data/archlog.%d.level.$LEVEL.%U_%T';    
delete noprompt expired backupset of archivelog all;    
release channel c1;    
#release channel c2;    
}


run{  
allocate channel c1 device type disk connect  'sys/
[email protected]
';    
#allocate channel c2 device type disk connect  'sys/[email protected]';    
crosscheck backupset of database;    
backup incremental level $LEVEL database format '$BACKUP_PATH/data/data.%d.level.$LEVEL.%U_%T';    
backup spfile tag='spfile' format '$BACKUP_PATH/data/spfile_%U_%T';   
backup current controlfile tag='control' format='$BACKUP_PATH/data/control_%U_%T';    
delete noprompt expired backupset of database;    
delete noprompt obsolete;    
release channel c1;    
#release channel c2;    
}    


run{    
allocate channel c1 device type disk connect  'sys/[email protected]';    
#allocate channel c2 device type disk connect  'sys/[email protected]';    
crosscheck backupset of archivelog all;    
backup archivelog  all format '$BACKUP_PATH/data/archlog.%d.level.$LEVEL.%U_%T';    
delete noprompt expired backupset of archivelog all; 
delete archivelog all completed before 'sysdate-7';   
release channel c1;    
#release channel c2;    
}


exit;    
EOF


else


$BIN/rman log $BACKUP_PATH/logs/level.$ORACLE_SID.$LEVEL.$DATE_2.log <<EOF


connect target /;  
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
run{    
allocate channel c1 device type disk connect  'sys/[email protected]';    
#allocate channel c2 device type disk connect  'sys/[email protected]';    
crosscheck backupset of archivelog all;    
backup archivelog all format '$BACKUP_PATH/data/archlog.%d.level.$LEVEL.%U_%T';    
delete noprompt expired backupset of archivelog all;    
release channel c1;    
#release channel c2;    
}


run{  
allocate channel c1 device type disk connect  'sys/[email protected]';    
#allocate channel c2 device type disk connect  'sys/[email protected]';  
crosscheck backupset of database ;    
backup incremental level $LEVEL database format '$BACKUP_PATH/data/data.%d.level.$LEVEL.%U_%T';    
backup spfile tag='spfile' format '$BACKUP_PATH/data/spfile_%U_%T'; 
backup current controlfile tag='control' format='$BACKUP_PATH/data/control_%U_%T';    
delete noprompt expired backupset of database ;    
delete noprompt obsolete ;    
release channel c1;    
#release channel c2;    
}


run{    
allocate channel c1 device type disk connect  'sys/[email protected]';    
#allocate channel c2 device type disk connect  'sys/[email protected]';    
crosscheck backupset of archivelog all;    
backup archivelog  all format '$BACKUP_PATH/data/archlog.%d.level.$LEVEL.%U_%T';    
delete noprompt expired backupset of archivelog all; 
delete archivelog all completed before 'sysdate-7';   
release channel c1;    
#release channel c2;    
}


exit;  
EOF


fi
################################################################################


3.新增計劃任務
crontab -e


00 1 * * 0            /data/rman_bak/scripts/rman_bak.sh 0    //週日01:00時完全備份
00 1 * * 1,2,3,4,5,6  /data/rman_bak/scripts/rman_bak.sh 1    //週一到週六01:00增量備份




4.配置監聽
tnsnames.ora新增如下:


ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = testdb-cluster-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )


ORCL1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.21.223)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
      (INSTANCE_NAME = orcl1)
    )
  )