ITPub博客

首页 > 数据库 > Oracle > rman恢复--丢失控制文件的恢复

rman恢复--丢失控制文件的恢复

原创 Oracle 作者:sun642514265 时间:2013-12-29 21:30:43 0 删除 编辑
注意:在恢复控制文件之前,必须知道目标数据库的DBID,关于数据库的dbid,有多中方式查找,方法如下

1.查询v$database获得 由于DBID在控制文件和数据文件中都存在记录,所以假如能够mount数据库就可以查询v$database视图获得. 
SQL> alter database mount; 
Database altered. 

SQL> select dbid from v$database;

      DBID
----------
1362763236

2.在nomount状态时 假如数据库配置了自动控制文件备份(Oracle9i以上),并且名称是缺省的,那么我们可以从自动备份文件获得DBID.
[oracle@oracle ~]$ cd /u01/app/oracle/backup/control/
[oracle@oracle control]$ ll
total 28800
-rw-r----- 1 oracle oinstall 9830400 Dec 24 18:44 c-1362763236-20131224-03
-rw-r----- 1 oracle oinstall 9830400 Dec 24 19:18 c-1362763236-20131224-04
-rw-r----- 1 oracle oinstall 9830400 Dec 24 19:52 c-1362763236-20131224-05

这里的1362763236就是DBID。

1:模拟文件丢失

由于控制文件在数据库open期间会被oracle进程锁定,无法直接删除,因为这里要先shutdown数据库,然后在删除控制文件。

SQL> show parameter control_file;

NAME                         TYPE     VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time          integer     7
control_files                    string     /u01/app/oracle/oradata/orcl/c
                              ontrol01.ctl, /u01/app/oracle/
                              flash_recovery_area/orcl/contr
                              ol02.ctl

找到该路径下,将cintrolfile删除掉。

[oracle@oracle ~]$ cd /u01/app/oracle/oradata/orcl/

[oracle@oracle orcl]$ rm control01.ctl
[oracle@oracle orcl]$ cd
[oracle@oracle ~]$ cd /u01/app/oracle/flash_recovery_area/
orcl/ ORCL/
[oracle@oracle ~]$ cd /u01/app/oracle/flash_recovery_area/orcl/
[oracle@oracle orcl]$ ll
total 9520
-rw-r----- 1 oracle oinstall 9748480 Dec 24 21:47 control02.ctl
[oracle@oracle orcl]$ rm control02.ctl
[oracle@oracle orcl]$ ll
total 0

将数据库启动到nomount状态

SQL> startup nomount;

ORACLE instance started.

Total System Global Area  835104768 bytes
Fixed Size              2217952 bytes
Variable Size            520095776 bytes
Database Buffers       310378496 bytes
Redo Buffers              2412544 bytes
SQL> 

由于控制文件丢失,肯定启动不到mount状态,因此将数据库启动到nomount状态。

2:恢复控制文件

登陆rman界面

oracle@oracle ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on 星期二 12月 24 21:51:12 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (not mounted)

目标数据库控制文件丢失,无法启动到mount状态,此处必须首先指定dbid


RMAN> set dbid=1362763236;

executing command: SET DBID


由于本人的备份是在nocatalog模式下进行的,因此备份信息,备份设置等都存储在目标数据库的控制文件中,现在控制文件丢失,相当于前面的一些配置也丢失了,用show all命令查看,可见之前所有的配置均恢复到了默认值,如下

RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default

此时恢复控制文件不能直接使用 restore controlfile from autobackup命令,因为自动备份的设置也丢失了,因此选泽显示指定控制文件备份集的方式恢复控制文件,如下

RMAN> restore controlfile from '/u01/app/oracle/backup/control/c-1362763236-20131224-05';   ---此路径是我备份controlfile路径

Starting restore at 2013-12-24 22:00:46
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/orcl/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/orcl/control02.ctl
Finished restore at 2013-12-24 22:00:49

RMAN> 

有了控制文件就可以将数据库启动到mount状态了


RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN>

由于只是丢失了控制文件,数据文件还在,因此并不需要对整个数据库进行修复操作(restore),只需要执行recover命令,重新应用备份控制文件之后 生成的那些重做日志即可。

 

RMAN> recover database;

Starting recover at 2013-12-24 22:06:08
Starting implicit crosscheck backup at 2013-12-24 22:06:08
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
Crosschecked 8 objects
Finished implicit crosscheck backup at 2013-12-24 22:06:10

Starting implicit crosscheck copy at 2013-12-24 22:06:10
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2013-12-24 22:06:10

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 78 is already on disk as file /u01/app/oracle/oradata/orcl/redo03.log
archived log file name=/u01/app/oracle/oradata/orcl/redo03.log thread=1 sequence=78
media recovery complete, elapsed time: 00:00:00
Finished recover at 2013-12-24 22:06:11

RMAN> 

如果上述命令都正常执行,那么就可以打开数据库了

RMAN> alter database open resetlogs;

database opened

由于是通过备份的控制文件恢复,因此打开数据库时,必须指定resetlogs。

切换PL SQL查看数据是否丢失。。










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

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

注册时间:2013-05-16

  • 博文量
    34
  • 访问量
    193498