本文描述:模拟未备份的数据文件丢失并恢复的过程。
试验过程:
注:试验前先将数据库全备或者0级备份
全备:
backup database format 'g:\rmanbak\db_%d_%T_%s.bak' plus archivelog format 'g:\rmanbak\arch_%d_%T_%s.bak';
0级备份:
backup incremental level 0 database format 'g:\rmanbak\db_%d_%T_%s.bak' plus archivelog format 'g:\rmanbak\arch_%d_%T_%s.bak';
(1)创建表空间tt,并用Scott账户在tt上创建表t
C:\Users\Administrator>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期三 6月 14 14:58:11 2017
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create tablespace tt datafile 'f:\oradata\tt01.dbf' size 10m;
Tablespace created.
SQL> conn scott/tiger
Connected.
SQL> create table t tablespace tt as select * from emp;
Table created.
SSQL> --删除表空间tt
SQL> conn / as sysdba
Connected.
SQL> alter system flush buffer_cache;
System altered.
SQL> alter system flush shared_pool;
System altered.
SQL> conn scott/tiger
Connected.
SQL> select * from t;
select * from t
*
ERROR at line 1:
ORA-00376: 此时无法读取文件 12
ORA-01110: 数据文件 12: 'F:\ORADATA\TT01.DBF'
SQL>
(2)登录ramn进行恢复
C:\Users\Administrator>rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on 星期三 6月 14 15:11:55 2017
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1468451227)
RMAN> run{
2> sql 'alter database datafile 12 offline';
3> restore datafile 12;
4> recover datafile 12;
5> sql 'alter database datafile 12 online';
6> }
using target database control file instead of recovery catalog
sql statement: alter database datafile 12 offline
Starting restore at 14-6月 -17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
--以往备份文件中并不包含此数据文件,restore时,rman先创建此文件(空的),然后再根据各种日志文件把数据恢复过来
creating datafile file number=12 name=F:\ORADATA\TT01.DBF
restore not done; all files read only, offline, or already restored
Finished restore at 14-6月 -17
Starting recover at 14-6月 -17
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 14-6月 -17
sql statement: alter database datafile 12 online
RMAN>
(3)登录sqlplus,数据成功恢复
SQL> conn scott/tiger
Connected.
SQL> select * from tab where tname='T';
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
T TABLE
SQL>
恢复成功!