| 導購 | 订阅 | 在线投稿
分享
 
 
 

巧用Oracle備份集在測試機上做不完全恢複

來源:互聯網  2008-06-14 05:54:18  評論

如果表的許多分區被意外drop,需要利用帶庫上的備份集在測試機上做不完全恢複,而具體日期需要達到一個特定的時間,那麽我們可以參考下文中的解決方法。

◆首先需要用logminer查出刪除語句:

uncompress /oracle/oradata/xxx/xxx.ARC.Z

...

begin

sys.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;

◆然後在生産庫上創建pfile:

create pfile='...' from spfile;

需要從帶庫上恢複rman備份集至生産機上,將此備份集FTP至測試機上,連同pfile文件.

在測試機上創建與生産機上相同目錄,admin ...

在測試機上創建新實例:

orapwd file=... password=xxx

然後修改pfile文件內容,改變control_files內容。

◆啓動新實例

export ORACLE_SID=xxx

sqlplus / as sysdba

startup nomount pfile='/home/oracle/init_xxx.ora';

create spfile from pfile='/home/oracle/init_xxx.ora';

exit

RMAN target sys/xxx

restore 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;

}

(注:發現單個datafile恢複不如整庫恢複快!)

sql 'alter database backup controlfile to trace';

shutdown immediate;

exit

然後修改controlfile文件內容,去掉不用的文件名

◆不完全恢複數據庫:

sqlplus / as sysdba

startup nomount;

◆重建控制文件

CREATE CONTROLFILE REUSE DATABASE "XXX" RESETLOGS ARCHIVELOG

MAXLOGFILES 40

MAXLOGMEMBERS 3

MAXDATAFILES 400

MAXINSTANCES 2

MAXLOGHISTORY 454

LOGFILE

GROUP 1 (

'/oracle/oradata/xxx/rdb_redo01a'

) SIZE 10M,

GROUP 2 (

'/oracle/oradata/xxx/rdb_redo02a'

) SIZE 10M

DATAFILE

'/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;

◆做數據恢複操作:

create table xxx as select xxx from xxx where xxx;

exp,ftp .dmp,imp

也可以如下所示,這樣會更簡單一些:

restore database;

recover database using backup controlfile until cancel;

alter database open resetlogs;

...

END!!!

如果表的許多分區被意外drop,需要利用帶庫上的備份集在測試機上做不完全恢複,而具體日期需要達到一個特定的時間,那麽我們可以參考下文中的解決方法。 ◆首先需要用logminer查出刪除語句: uncompress /oracle/oradata/xxx/xxx.ARC.Z ... begin sys.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; ◆然後在生産庫上創建pfile: create pfile='...' from spfile; 需要從帶庫上恢複rman備份集至生産機上,將此備份集FTP至測試機上,連同pfile文件. 在測試機上創建與生産機上相同目錄,admin ... 在測試機上創建新實例: orapwd file=... password=xxx 然後修改pfile文件內容,改變control_files內容。 ◆啓動新實例 export ORACLE_SID=xxx sqlplus / as sysdba startup nomount pfile='/home/oracle/init_xxx.ora'; create spfile from pfile='/home/oracle/init_xxx.ora'; exit RMAN target sys/xxx restore 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; } (注:發現單個datafile恢複不如整庫恢複快!) sql 'alter database backup controlfile to trace'; shutdown immediate; exit 然後修改controlfile文件內容,去掉不用的文件名 ◆不完全恢複數據庫: sqlplus / as sysdba startup nomount; ◆重建控制文件 CREATE CONTROLFILE REUSE DATABASE "XXX" RESETLOGS ARCHIVELOG MAXLOGFILES 40 MAXLOGMEMBERS 3 MAXDATAFILES 400 MAXINSTANCES 2 MAXLOGHISTORY 454 LOGFILE GROUP 1 ( '/oracle/oradata/xxx/rdb_redo01a' ) SIZE 10M, GROUP 2 ( '/oracle/oradata/xxx/rdb_redo02a' ) SIZE 10M DATAFILE '/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; ◆做數據恢複操作: create table xxx as select xxx from xxx where xxx; exp,ftp .dmp,imp 也可以如下所示,這樣會更簡單一些: restore database; recover database using backup controlfile until cancel; alter database open resetlogs; ... END!!!
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有