DATA GUARD主庫丟失資料檔案的恢復(3)

space6212發表於2019-07-20

在DATAGUARD中,如果有備份,主庫出現問題時,有多種恢復方式可選:
1、從備庫複製相關檔案到主庫上恢復
2、複製備庫備份到主庫還原恢復
3、從主庫備份還原恢復

本文主要討論10G DATAGUARD中,主庫丟失資料檔案時,利用備庫的備份恢復主庫。



一、在備庫執行備份
[oracle@standby ~]$ rman target /

Recovery Manager: Release 10.2.0.3.0 - Production on Tue Jul 3 15:02:06 2007

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: PRIMARY (DBID=1463588919, not open)

RMAN> backup datafile 1 format '/u01/backup/%U';

Starting backup at 03-JUL-07
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=203 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/oracle/oradata/primary/system01.dbf
channel ORA_DISK_1: starting piece 1 at 03-JUL-07
channel ORA_DISK_1: finished piece 1 at 03-JUL-07
piece handle=/u01/backup/05iltlui_1_1 tag=TAG20070703T150346 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 03-JUL-07
channel ORA_DISK_1: finished piece 1 at 03-JUL-07
piece handle=/u01/backup/06iltlvc_1_1 tag=TAG20070703T150346 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:06
Finished backup at 03-JUL-07

RMAN> exit

二、在主庫刪除檔案,模擬丟失檔案
[oracle@primary primary]$ rm system01.dbf
SQL> startup
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 1260696 bytes
Variable Size 134218600 bytes
Database Buffers 29360128 bytes
Redo Buffers 2932736 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/oracle/oradata/primary/system01.dbf'

三、複製備庫的備份到主庫上
[oracle@standby backup]$ scp 05iltlui_1_1 10.2.98.10:`pwd`
oracle@10.2.98.10's password:
05iltlui_1_1 100% 129MB 2.4MB/s 00:53

四、用備庫備份進行恢復
由於備份是在備庫做的,所以主庫的控制檔案不包含備庫的備份資訊,所以,不能使用常規的restore、recover的方式恢復,需要用dbms_backup_restore包。

SQL> DECLARE
2 devtype varchar2(256);
3 done boolean;
4 BEGIN
5 devtype := sys.dbms_backup_restore.deviceAllocate(type => '',
6 ident => 't1');
7 sys.dbms_backup_restore.restoreSetDatafile;
8 sys.dbms_backup_restore.restoreDatafileTo(dfnumber => 01,toname=> '/u01/oracle/oradata/primary/system01.dbf');
9 sys.dbms_backup_restore.restoreBackupPiece(done => done,handle => '/u01/backup/05iltlui_1_1',params => null);
10 sys.dbms_backup_restore.deviceDeallocate;
11 END;
12 /

PL/SQL procedure successfully completed.

SQL> recover datafile 1;
Media recovery complete.

SQL> alter database open;

Database altered.

五、驗證恢復
SQL> alter database open;

Database altered.

SQL> create table test4(id int);

Table created.

SQL> alter system switch logfile;

System altered.

此時,在備庫檢視alert日誌:
RFS[3]: Successfully opened standby log 4: '/u01/oracle/oradata/primary/standbyredo04.log'
Tue Jul 3 15:56:16 2007
Media Recovery Log /u01/archivelog/1_60_626106231.dbf
Media Recovery Waiting for thread 1 sequence 61 (in transit)

在備庫執行如下操作:
SQL> alter database recover managed standby database cancel;

Database altered.

SQL> alter database open;

Database altered.

SQL> select * from test4;

no rows selected

可見,DATAGUARD恢復正常。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/231499/viewspace-63833/,如需轉載,請註明出處,否則將追究法律責任。

相關文章