巧用Oracle備份集在測(cè)試機(jī)上做不完全恢復(fù)
◆首先需要用logminer查出刪除語(yǔ)句:
uncompress /oracle/oradata/xxx/xxx.ARC.Z ...beginsys.dbms_logmnr.add_logfile('/oracle/oradata/xxx/xxx.ARC');...end;begin sys.dbms_logmnr.start_logmnr(Options => sys.dbms_logmnr.DICT_FROM_ONLINE_CATALOG); end;create table xsb_logminer_1 as select timestamp, seg_name,operation, sql_redo from V$LOGMNR_CONTENTS where seg_owner='XXX' and operation='DDL' and sql_redo like 'ALTER TABLE XXX DROP PARTITION %';BEGIN sys.dbms_logmnr.end_logmnr();END;
◆然后在生產(chǎn)庫(kù)上創(chuàng)建pfile:
create pfile='...' from spfile;
需要從帶庫(kù)上恢復(fù)rman備份集至生產(chǎn)機(jī)上,將此備份集FTP至測(cè)試機(jī)上,連同pfile文件.
在測(cè)試機(jī)上創(chuàng)建與生產(chǎn)機(jī)上相同目錄,admin ...
在測(cè)試機(jī)上創(chuàng)建新實(shí)例:
orapwd file=... password=xxx
然后修改pfile文件內(nèi)容,改變control_files內(nèi)容。
◆啟動(dòng)新實(shí)例
export ORACLE_SID=xxxsqlplus / as sysdbastartup nomount pfile='/home/oracle/init_xxx.ora';create spfile from pfile='/home/oracle/init_xxx.ora';exitRMAN target sys/xxxrestore controlfile from '...';startup mount--crosscheck backup;list backup;run {set newname for datafile 1 to '/oracle/oradata/xxx/system01.dbf';set newname for datafile 2 to '/oracle/oradata/xxx/undo01.dbf';set newname for datafile 3 to '/oracle/oradata/xxx/sysaux01.dbf';set newname for datafile 6 to '/oracle/oradata/xxx/pay_ts01.dbf';restore datafile 1;restore datafile 2;restore datafile 3; restore datafile 6;}(注:發(fā)現(xiàn)單個(gè)datafile恢復(fù)不如整庫(kù)恢復(fù)快!)sql 'alter database backup controlfile to trace';shutdown immediate;exit
然后修改controlfile文件內(nèi)容,去掉不用的文件名
◆不完全恢復(fù)數(shù)據(jù)庫(kù):
sqlplus / as sysdbastartup nomount;
◆重建控制文件
CREATE CONTROLFILE REUSE DATABASE 'XXX' RESETLOGS ARCHIVELOGMAXLOGFILES 40MAXLOGMEMBERS 3MAXDATAFILES 400MAXINSTANCES 2MAXLOGHISTORY 454LOGFILEGROUP 1 ('/oracle/oradata/xxx/rdb_redo01a') SIZE 10M,GROUP 2 ('/oracle/oradata/xxx/rdb_redo02a') SIZE 10MDATAFILE '/oracle/oradata/xxx/system01.dbf','/oracle/oradata/xxx/undo01.dbf','/oracle/oradata/xxx/sysaux01.dbf','/oracle/oradata/xxx/pay_ts01.dbf'CHARACTER SET ZHS16GBK;recover database until cancel using backup controlfile;...alter database open resetlogs;
◆做數(shù)據(jù)恢復(fù)操作:
create table xxx as select xxx from xxx where xxx;exp,ftp .dmp,imp
也可以如下所示,這樣會(huì)更簡(jiǎn)單一些:
restore database;recover database using backup controlfile until cancel;alter database open resetlogs;...END!!!
