ITPub博客

首页 > Linux操作系统 > Linux操作系统 > rman 恢复实例

rman 恢复实例

原创 Linux操作系统 作者:Jujay 时间:2011-10-14 17:16:24 0 删除 编辑
1. 模拟: 数据文件丢失

1) 备份数据库
RMAN> backup database format 'H:\INTEL_DB_DUMPS\O07DMS0\rman\O07DMS0_full_%U';
2)模拟数据库操作
A105024@O07DMS0>create table test (id number);

Table created.

A105024@O07DMS0>insert into test values(1);

1 row created.

A105024@O07DMS0>commit;

Commit complete.

3) 模拟数据文件丢失
RMAN> shutdown immediate;
在OS删除文件: I:\INTEL_DATA\O07DMS0\USERS_01.O07DMS0
尝试启动数据库失败:
RMAN> startup

connected to target database (not started)
Oracle instance started
database mounted
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 10/14/2011 05:03:25
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: 'I:\INTEL_DATA\O07DMS0\USERS_01.O07DMS0'

4) 执行恢复
RMAN> restore datafile 4;

Starting restore at 14-OCT-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=135 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to I:\INTEL_DATA\O07DMS0\USERS_01.O07DMS0
channel ORA_DISK_1: reading from backup piece H:\INTEL_DB_DUMPS\O07DMS0\RMAN\O07DMS0_FULL_1KMP27FQ_1_1
channel ORA_DISK_1: piece handle=H:\INTEL_DB_DUMPS\O07DMS0\RMAN\O07DMS0_FULL_1KMP27FQ_1_1 tag=TAG20111014T045833
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 14-OCT-11

RMAN> recover datafile 4;

Starting recover at 14-OCT-11
using channel ORA_DISK_1

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

Finished recover at 14-OCT-11

5) 打开数据库验证
RMAN> alter database open;

database opened

A105024@O07DMS0>select * from test;

        ID
----------
         1

2. 模拟:控制文件丢失

1) 备份数据库
RMAN> backup database format 'H:\INTEL_DB_DUMPS\O07DMS0\rman\O07DMS0_full_%U';
2)模拟数据库操作
A105024@O07DMS0>create table test (id number);

Table created.

A105024@O07DMS0>insert into test values(1);

1 row created.

A105024@O07DMS0>commit;

Commit complete.
3) 模拟控制文件丢失
RMAN> shutdown immediate;
在OS删除文件所有的控制文件:
I:\INTEL_DATA\O07DMS0\CONTROL_01.O07DMS0
I:\INTEL_DATA\O07DMS0\CONTROL_02.O07DMS0
I:\INTEL_DATA\O07DMS0\CONTROL_03.O07DMS0
尝试启动数据库失败:
RMAN> startup

connected to target database (not started)
Oracle instance started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 10/17/2011 00:59:29
ORA-00205: error in identifying control file, check alert log for more info

由于控制文件丢失,数据库最能启动到nomount状态:
4) 恢复控制文件
RMAN> set dbid=3672122205

executing command: SET DBID

RMAN> restore controlfile from 'H:\INTEL_DB_DUMPS\O07DMS0\rman\CF_O07DMS0_C-3672122205-20111017-00';

Starting restore at 17-OCT-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=I:\INTEL_DATA\O07DMS0\CONTROL_01.O07DMS0
output file name=I:\INTEL_DATA\O07DMS0\CONTROL_02.O07DMS0
output file name=I:\INTEL_DATA\O07DMS0\CONTROL_03.O07DMS0
Finished restore at 17-OCT-11

5) 恢复数据库
有了控制文件,便可以mount数据库了:
RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

重新应用在备份的控制文件后生成的redo log即可:

RMAN> recover database;

Starting recover at 17-OCT-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK

starting media recovery

archived log for thread 1 with sequence 4 is already on disk as file I:\INTEL_DATA\O07DMS0\REDO01_B.O07DMS0
archived log file name=I:\INTEL_DATA\O07DMS0\REDO01_B.O07DMS0 thread=1 sequence=4
media recovery complete, elapsed time: 00:00:00
Finished recover at 17-OCT-11

6) 打开数据库验证

恢复控制文件后,必须以resetlog打开数据库:

RMAN> alter database open resetlogs;

database opened

A105024@O07DMS0>select * from test;

        ID
----------
         1

3. 模拟:inactive online redo log丢失

1) 查出哪些是非当前的online redo log
A105024@O07DMS0>select GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS from v$log;

    GROUP#    THREAD#  SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------------
         1          1          1 YES INACTIVE
         2          1          2 YES INACTIVE
         3          1          3 NO  CURRENT

Group 1, 2都是非当前的online redo log, 查出其对应的redo log file

A105024@O07DMS0>select GROUP#,MEMBER from v$logfile;

    GROUP# MEMBER
---------- --------------------------------------------------------------------------------
         1 J:\INTEL_LOG\O07DMS0\REDO01_A.O07DMS0
         1 I:\INTEL_DATA\O07DMS0\REDO01_B.O07DMS0
         2 J:\INTEL_LOG\O07DMS0\REDO02_A.O07DMS0
         2 I:\INTEL_DATA\O07DMS0\REDO02_B.O07DMS0
         3 J:\INTEL_LOG\O07DMS0\REDO03_A.O07DMS0
         3 I:\INTEL_DATA\O07DMS0\REDO03_B.O07DMS0

2) 模拟online redo log 丢失
SQL> shutdown immediate;
在OS层面手动删除Group 1的两个logfile:
J:\INTEL_LOG\O07DMS0\REDO01_A.O07DMS0
I:\INTEL_DATA\O07DMS0\REDO01_B.O07DMS0
启动数据库失败:
SQL> startup
ORACLE instance started.

Total System Global Area  535662592 bytes
Fixed Size                  1384752 bytes
Variable Size             394268368 bytes
Database Buffers          134217728 bytes
Redo Buffers                5791744 bytes
Database mounted.
ORA-03113: end-of-file on communication channel
Process ID: 1428
Session ID: 9 Serial number: 5

数据库只能启动到mount状态。

3) 修复online redo log
由于丢失的online redo log是inactive,解决方案很简单,直接清楚并重做日志即可:
SQL> startup mount
ORACLE instance started.

Total System Global Area  535662592 bytes
Fixed Size                  1384752 bytes
Variable Size             394268368 bytes
Database Buffers          134217728 bytes
Redo Buffers                5791744 bytes
Database mounted.

SQL> alter database clear logfile group 1;

Database altered.

此时group 1的状态变成了unused:

SQL> select GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS from v$log;

    GROUP#    THREAD#  SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------------
         1          1          0 YES UNUSED
         3          1          3 NO  CURRENT
         2          1          2 YES INACTIVE

4) 打开数据库

SQL> alter database open;

Database altered.

4. 模拟:active或current online redo log丢失

1) 查出哪些是active 或 current 的online redo log

SQL> select GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS from v$log;

    GROUP#    THREAD#  SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------------
         1          1          4 YES ACTIVE
         2          1          5 NO  CURRENT
         3          1          3 YES INACTIVE

Group 1 是active, Group 2是current。

SQL>select GROUP#,MEMBER from v$logfile;

    GROUP# MEMBER
---------- --------------------------------------------------------------------------------
         1 J:\INTEL_LOG\O07DMS0\REDO01_A.O07DMS0
         1 I:\INTEL_DATA\O07DMS0\REDO01_B.O07DMS0
         2 J:\INTEL_LOG\O07DMS0\REDO02_A.O07DMS0
         2 I:\INTEL_DATA\O07DMS0\REDO02_B.O07DMS0
         3 J:\INTEL_LOG\O07DMS0\REDO03_A.O07DMS0
         3 I:\INTEL_DATA\O07DMS0\REDO03_B.O07DMS0

2) 模拟online redo log 丢失
SQL> shutdown abort;
在OS层面手动删除Group 1的两个logfile:
J:\INTEL_LOG\O07DMS0\REDO01_A.O07DMS0
I:\INTEL_DATA\O07DMS0\REDO01_B.O07DMS0
启动数据库失败:
SQL> startup mount;
ORACLE instance started.

Total System Global Area  535662592 bytes
Fixed Size                  1384752 bytes
Variable Size             394268368 bytes
Database Buffers          134217728 bytes
Redo Buffers                5791744 bytes
Database mounted.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'I:\INTEL_DATA\O07DMS0\REDO01_B.O07DMS0'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.
ORA-00312: online log 1 thread 1: 'J:\INTEL_LOG\O07DMS0\REDO01_A.O07DMS0'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.

数据库只能启动到mount状态。

3) 尝试直接修复online redo log
由于丢失的online redo log是active,直接清楚并重做日志失败,因为crash recovery还需要丢失的日志文件。
SQL> alter database clear logfile group 1;
alter database clear logfile group 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance o07dms0 (thread 1)
ORA-00312: online log 1 thread 1: 'J:\INTEL_LOG\O07DMS0\REDO01_A.O07DMS0'
ORA-00312: online log 1 thread 1: 'I:\INTEL_DATA\O07DMS0\REDO01_B.O07DMS0'

4) 执行不完全恢复

修改一个隐藏参数:
SQL> alter system set "_allow_resetlogs_corruption"=true scope=spfile;

System altered.
重启让其生效:
SQL> shutdown immediate
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  535662592 bytes
Fixed Size                  1384752 bytes
Variable Size             394268368 bytes
Database Buffers          134217728 bytes
Redo Buffers                5791744 bytes
Database mounted.

对数据库进行不完全恢复:
SQL> recover database until cancel;
ORA-10879: error signaled in parallel recovery slave
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: 'I:\INTEL_DATA\O07DMS0\SYSTEM_01.O07DMS0'

以resetlogs打开数据库:

SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-00600: internal error code, arguments: [2663], [0], [8434157], [0],
[8434163], [], [], [], [], [], [], []
Process ID: 4168
Session ID: 125 Serial number: 5

出现了ORA-00600错误,这是在意料之中的事,重新再启动一次即可:

SQL> startup
ORACLE instance started.

Total System Global Area  535662592 bytes
Fixed Size                  1384752 bytes
Variable Size             394268368 bytes
Database Buffers          134217728 bytes
Redo Buffers                5791744 bytes
Database mounted.
Database opened.

注意:这是没办法中的办法,且会造成部分数据丢失!!!











来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26277071/viewspace-709234/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: rman 恢复
请登录后发表评论 登录
全部评论

注册时间:2011-09-14

  • 博文量
    93
  • 访问量
    291022