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

space6212發表於2019-03-15

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

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

這種方式比較簡單,和單機的備份恢復沒什麼區別。


一、在主庫執行備份
[oracle@primary backup]$ rman target /

Recovery Manager: Release 10.2.0.3.0 - Production on Tue Jul 3 11:50:33 2007

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

connected to target database: PRIMARY (DBID=1463588919)

RMAN> backup database 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=193 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00005 name=/u01/oracle/oradata/primary/suk01.dbf
input datafile fno=00001 name=/u01/oracle/oradata/primary/system01.dbf
input datafile fno=00002 name=/u01/oracle/oradata/primary/undotbs01.dbf
input datafile fno=00003 name=/u01/oracle/oradata/primary/sysaux01.dbf
input datafile fno=00004 name=/u01/oracle/oradata/primary/users01.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/01iltal9_1_1 tag=TAG20070703T115105 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
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/02iltan1_1_1 tag=TAG20070703T115105 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 03-JUL-07
RMAN> exit

Recovery Manager complete.

二、在主庫刪除檔案,模擬丟失檔案
[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@primary backup]$ rman target /

Recovery Manager: Release 10.2.0.3.0 - Production on Tue Jul 3 11:55:04 2007

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

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

RMAN> restore datafile 1;

Starting restore at 03-JUL-07
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=210 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/oracle/oradata/primary/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/01iltal9_1_1
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/backup/01iltal9_1_1 tag=TAG20070703T115105
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 03-JUL-07

RMAN> recover datafile 1;

Starting recover at 03-JUL-07
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 03-JUL-07

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

Database altered.

SQL> create table test3(id int);

Table created.

SQL> alter system switch logfile;

System altered.

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

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

Database altered.

SQL> alter database open;

Database altered.

SQL> select * from test3;

no rows selected

可見,DATAGUARD恢復正常。

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

相關文章