ORACLE RMAN恢复测试脚本

此恢复测试脚本在redhat6.5环境,oracle11g可以直接运行:

次恢复测试脚本省略了恢复pfile文件的步骤,pfile由于恢复至做一次,以后的恢复测试不需要再恢复pfile,因此不需要脚本化。


SID=prdtestdb

export ORACLE_SID=$SID


logfile=shrman_$SID.log


#设置rman备份文件目录,和要恢复的数据文件的目录

SrcDbBackup=/dbfile2/backupprdtestdb
DstDbRecover=/dbfile1/database/prdtestdb

#获取rman本分目录内的control文件名,有可能有多个,此处取第一个
ControlFileName=`ls *.ctb|head -n 1`


#恢复rman文件

cmdRestoreControl="restore controlfile to '$DstDbRecover/control1.ctl' from '$SrcDbBackup/$ControlFileName';";


echo "restore control cmd is:">$logfile
echo $cmdRestoreControl >>$logfile




echo "startup nomount
exit" > temp.sql


echo "




startup nomount:">>$logfile
sqlplus -S / as sysdba @temp.sql >>$logfile 2>&1




echo "connect target /;
RUN {
allocate channel d1 type disk ;
$cmdRestoreControl
release channel d1;
}
exit" > controlrestore.rman


nohup rman cmdfile controlrestore.rman msglog temp.log >>$logfile 2>&1


cat temp.log >>$logfile




echo "restore control file success" >>$logfile




echo "alter database mount;
exit" > temp.sql




echo "




alter database mount:">>$logfile
sqlplus -S / as sysdba @temp.sql >>$logfile 2>&1








echo "connect target /;
RUN {
allocate channel d1 type disk ;
catalog start with '$SrcDbBackup';
release channel d1;
}
exit" > catalog.rman




nohup rman cmdfile catalog.rman msglog temp.log >>$logfile 2>&1




cat temp.log >>$logfile

#此处为获取所有数据文件名称,并获取将数据文件名称重命名rman脚本。(恢复库和原库的数据文件位置或文件名不一定相同,所以需要重命名)

echo 'set wrap off SQLBLANKLINES ON;
set verify off  pagesize 0  echo off 
set feedback off  linesize 10000  long 5000  trimout on;
set trimspool on  arraysize 20
set trims on space 0  newpage none numwidth 12  serveroutput on
set wrap off  SQLBLANKLINES ON
set term off
spool restore'$SID'.rman
select '"'connect target /;'"'||chr(10)||
'"'RUN {'"'||chr(10)||
'"'set command id to '"'||chr(39)||'"'123'"'||chr(39)||'"';'"'||chr(10)
||'"'allocate channel d1 type disk ;'"'||chr(10)
||'"'allocate channel d2 type disk ;'"'||chr(10)
||'"'allocate channel d3 type disk ;'"'||chr(10)
||'"'allocate channel d4 type disk ;'"'||chr(10) from dual;
select '"'SET NEWNAME FOR DATAFILE '"'||chr(39)||name||chr(39)||'"' to '"'||chr(39)||'"'$DstDbRecover/'"'||substr(name,instr(name, '"'/'"', -1)+1, length(name)-instr(name, '"'/'"', -1))||chr(39)||'"';'"' from V$datafile;
select '"'restore database;'"'||chr(10)
||'"'SWITCH DATAFILE ALL;'"'||chr(10)
||'"'release channel d1;'"'||chr(10)
||'"'release channel d2;'"'||chr(10)
||'"'release channel d3;'"'||chr(10)
||'"'release channel d4;'"'||chr(10)
||'"'}'"'||chr(10)
||'"'exit'"'||chr(10) from dual;
spool off
exit' > temp.sql




sqlplus -S / as sysdba @temp.sql >>$logfile 2>&1


echo 'restore database begin...'>>$logfile


nohup rman cmdfile restore$SID.rman msglog restore$SID.log >>$logfile 2>&1






echo "connect target /;
RUN {
allocate channel d1 type disk ;
recover database;
release channel d1;
}
exit" > recover$SID.rman


echo 'recover database begin...'>>$logfile
nohup rman cmdfile recover$SID.rman msglog recover$SID.log >>$logfile 2>&1





#此处为重命名logfile


echo 'set wrap off SQLBLANKLINES ON;
set verify off  pagesize 0  echo off 
set feedback off  linesize 10000  long 5000  trimout on;
set trimspool on  arraysize 20
set trims on space 0  newpage none numwidth 12  serveroutput on
set wrap off  SQLBLANKLINES ON
set term off
spool rename.sql
select '"'ALTER DATABASE RENAME FILE '"'||chr(39)||member||chr(39)||'"' to '"'||chr(39)||'"'$DstDbRecover/'"'||substr(member,instr(member, '"'/'"', -1)+1, length(member)-instr(member, '"'/'"', -1))||chr(39)||'"';'"' aaa from V$logfile where type='"'ONLINE'"';


select '"'alter database drop logfile group '"'||group#||'"';'"' aaa from V$logfile where type='"'STANDBY'"';
select '"'exit'"' from dual;
spool off
exit' > temp.sql




echo 'rename logfile begin ...'>>$logfile
sqlplus -S / as sysdba @temp.sql >>$logfile 2>&1


echo 'drop standby logfile begin ...'>>$logfile
sqlplus -S / as sysdba @rename.sql >>$logfile 2>&1






echo "connect target /;
RUN {
allocate channel d1 type disk ;
ALTER DATABASE OPEN RESETLOGS;
release channel d1;
}
exit" > Open$SID.rman


echo 'open db resetlogs begin ...'>>$logfile
nohup rman cmdfile Open$SID.rman msglog Open$SID.log >>$logfile 2>&1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值