ITPub博客

首页 > Linux操作系统 > Linux操作系统 > DATA GUARD主库丢失数据文件的恢复(3)

DATA GUARD主库丢失数据文件的恢复(3)

原创 Linux操作系统 作者:space6212 时间:2019-07-20 20:06:02 0 删除 编辑

在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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2005-01-25

  • 博文量
    245
  • 访问量
    166243