今天做了个实验,模拟控制文件完全丢失后,通过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
1. 备份数据库
-
[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/0sq7df6f_1_1.bak,
注意上面的 “DBID=1396675707” ,这个在后面控制文件恢复时会用到的
2. 模拟控制文件丢失
1) 将控制文件重重命名
-
[oracle@REDHAT6 ORCL]$ pwd
-
/u01/app/oradata/ORCL
- [oracle@REDHAT6 ORCL]$ mv control01.ctl control01_bak.ctl
-
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
3. 恢复控制文件
1) 将数据库启动到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
-
[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
这里有两点需要注意下,
首先,rman连接进来后,DBID是未知的,要先执行 RMAN> set DBID=1396675707 (DBID的值在上面rman备份时是有的),
其次,还原的备份集要正确,在进行rman备份时,通过 list backup 可以看到控制文件所在的备份集。
4. 恢复数据库
1) 将数据库启动到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
现在数据库已经正常启动了!