控制文件完全丢失后进行恢复
今天做了个实验,模拟控制文件完全丢失后,通过rman备份来进行还原。
实验环境:
操作系统环境:
[oracle@REDHAT6 tmp]$ lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: OracleServer
Description: Oracle Linux Server release 6.5
Release: 6.5
Codename: n/a
数据库环境:
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> show parameter control_files;
NAME TYPE VALUE
-------------------- ----------- ------------------------------
control_files string /u01/app/oradata/ORCL/control01.ctl
这里为了实验方便,所以控制文件只设置了一份。
- 备份数据库
[oracle@REDHAT6 tmp]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Wed May 20 10:59:55 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1396675707)
RMAN> backup database format '/home/oracle/db_backup/%U.bak';
RMAN> list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21 Full 1.32G DISK 00:01:44 20-MAY-15
BP Key: 21 Status: AVAILABLE Compressed: NO Tag: TAG20150520T110508
Piece Name: /home/oracle/db_backup/0rq7df35_1_1.bak
List of Datafiles in backup set 21
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/system01.dbf
2 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/sysaux01.dbf
3 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/undotbs01.dbf
4 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/users01.dbf
5 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/example01.dbf
6 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/df1.dbf
7 Full 3149096 20-MAY-15 /u01/app/oradata/df2.dbfdf2
8 Full 3149096 20-MAY-15 /u01/app/oradata/rman1.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
22 Full 9.39M DISK 00:00:01 20-MAY-15
BP Key: 22 Status: AVAILABLE Compressed: NO Tag: TAG20150520T110508
Piece Name: /home/oracle/db_backup/0sq7df6f_1_1.bak
SPFILE Included: Modification time: 20-MAY-15
SPFILE db_unique_name: ORCL
Control File Included: Ckp SCN: 3149581 Ckp time: 20-MAY-15
数据文件备份在:/home/oracle/db_backup/0rq7df35_1_1.bak,
控制文件和参数文件备份在:/home/oracle/db_backup/0sq7df6f_1_1.bak,
注意上面的 “DBID=1396675707” ,这个在后面控制文件恢复时会用到的
注:在实际生产环境下,不会给你机会去记住这个DBID,可以通过其他方式去查到DBID,查询方法会在文章最后给出。
- 模拟控制文件丢失
- 将控制文件重重命名
[oracle@REDHAT6 ORCL]$ pwd
/u01/app/oradata/ORCL
[oracle@REDHAT6 ORCL]$ mv control01.ctl control01_bak.ctl
2) 重启数据库
SQL> startup force;
ORACLE instance started.
Total System Global Area 889389056 bytes
Fixed Size 2233480 bytes
Variable Size 494930808 bytes
Database Buffers 385875968 bytes
Redo Buffers 6348800 bytes
ORA-00205: error in identifying control file, check alert log for more info
这里控制文件已经报错了,无法指定控制文件
- 恢复控制文件
- 将数据库启动到nomount状态
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 889389056 bytes
Fixed Size 2233480 bytes
Variable Size 494930808 bytes
Database Buffers 385875968 bytes
Redo Buffers 6348800 bytes
2) 通过rman还原控制文件
[oracle@REDHAT6 ORCL]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Wed May 20 11:27:37 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (not mounted)
RMAN> set DBID=1396675707
executing command: SET DBID
RMAN> restore controlfile from '/home/oracle/db_backup/0sq7df6f_1_1.bak';
Starting restore at 20-MAY-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oradata/ORCL/control01.ctl
Finished restore at 20-MAY-15
由于数据库是nomount状态,所以rman连接进来的时候,ORCL (not mounted)。
这里有两点需要注意下,
首先,rman连接进来后,DBID是未知的,要先执行 RMAN> set DBID=1396675707 (DBID的值在上面rman备份时是有的),
其次,还原的备份集要正确,在进行rman备份时,通过 list backup 可以看到控制文件所在的备份集。
- 恢复数据库
- 将数据库启动到mount状态
SQL> alter database mount
- 还原数据库, 恢复数据库 和 启动数据库
RMAN> restore database;
Starting restore at 20-MAY-15
Starting implicit crosscheck backup at 20-MAY-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=125 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 20-MAY-15
Starting implicit crosscheck copy at 20-MAY-15
using channel ORA_DISK_1
Finished implicit crosscheck copy at 20-MAY-15
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
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 00001 to /u01/app/oradata/ORCL/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oradata/ORCL/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oradata/ORCL/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oradata/ORCL/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oradata/ORCL/example01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oradata/ORCL/df1.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oradata/df2.dbfdf2
channel ORA_DISK_1: restoring datafile 00008 to /u01/app/oradata/rman1.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/db_backup/0uq7dmht_1_1
channel ORA_DISK_1: piece handle=/home/oracle/db_backup/0uq7dmht_1_1 tag=TAG20150520T131228
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 20-MAY-15
RMAN> recover database;
Starting recover at 20-MAY-15
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oradata/ORCL/redo01.log
archived log file name=/u01/app/oradata/ORCL/redo01.log thread=1 sequence=1
media recovery complete, elapsed time: 00:00:01
Finished recover at 20-MAY-15
RMAN> sql 'alter database open resetlogs';
sql statement: alter database open resetlogs
也可以在sqlplus界面进行alter database open resetlogs操作。
现在数据库已经正常启动了!
以上部分转载为ITPUB博主warren20的文章《控制文件丢失通过rman备份恢复》
链接:http://blog.itpub.net/30150152/viewspace-1664021/
----------------------------------------------------华丽分割线---------------------------------------------------------
PS:查看DBID方法
在进行数据库恢复的过程中,很多时候我们需要知道Oracle数据库的DBID,通常有以下几种方法可以获得数据库的DBID.
1.查询v$database获得
由于DBID在控制文件和数据文件中都存在记录,所以如果能够mount数据库就可以查询v$database视图获得.
SQL> select status from v$instance;
STATUS
MOUNTED
SQL> select dbid from v$database;
DBID
1742847260
2.在nomount状态时
如果数据库配置了自动控制文件备份,并且名称是缺省的,那么我们可以从自动备份文件获得DBID.
CONFIGURE CONTROLFILE AUTOBACKUP ON; 记住在rman中要开启自动备份控制文件
[oracle@node1 dbs]$ cd $ORACLE_HOME/dbs
[oracle@node1 dbs]$ ls -l c*
-rw-r----- 1 oracle dba 9830400 Nov 22 23:22 c-1742847260-20151122-00
这里的1742847260就是DBID。
3.从rman中也可以看到dbid
需要或缺DBID进行恢复通常是因为丢失了所有的控制文件.在恢复时会遇到错误.
[oracle@node1 dbs]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sun Nov 22 23:34:34 2015
Copyright © 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: NODE1 (DBID=1742847260)
可以在数据库正常的时候记录dbid
从数据文件中也可以读取dbid,不过记住以上3种简单方法,就够用了!
————————————————
版权声明:本文为CSDN博主「zw_hard」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhengwei125/article/details/50440815