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