除了关键数据文件system,undo 两个,其他的非关键数据文件丢失后的恢复。
1 先建表空间example
SQL> select file#,name,status from v$datafile;
FILE# NAME STATUS
---------- -------------------------------------------------- -------
1 /u01/oracle/oradata/orcl/system01.dbf SYSTEM
2 /u01/oracle/oradata/orcl/sysaux01.dbf ONLINE
3 /u01/oracle/oradata/orcl/undotbs01.dbf RECOVER
4 /u01/oracle/oradata/orcl/users01.dbf ONLINE
5 /u01/oracle/oradata/orcl/user02.dbf ONLINE
6 /u01/oracle/oradata/orcl/tmpspace0327 ONLINE
7 /u01/oracle/oradata/orcl/undotbs02.dbf ONLINE
8 /u01/oracle/oradata/orcl/examp01.dbf ONLINE
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
USERS ONLINE
UNDOTBS2 ONLINE
USER02 ONLINE
TMP_SPACE_0327 ONLINE
TEMP ONLINE
EXAMPLE ONLINE
2 在表空间example 中创建一个表
SQL> create table employess tablespace EXAMPLE as select * from scott.emp;
Table created.
3 在rman中备份数据文件examp01.dbf
RMAN> backup datafile 8;
Starting backup at 09-APR-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=150 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00008 name=/u01/oracle/oradata/orcl/examp01.dbf
channel ORA_DISK_1: starting piece 1 at 09-APR-17
channel ORA_DISK_1: finished piece 1 at 09-APR-17
piece handle=/tmp/0rs19lr3_1_1 tag=TAG20170409T221915 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-APR-17
4 删除数据文件examp01.dbf
SQL> ho rm -rf /u01/oracle/oradata/orcl/examp01.dbf;
4 在rman 中用脚本进行恢复
[oracle@dghost ~]$ cat /tmp/re.sql
run
{
sql 'alter database datafile 8 offline';
restore datafile 8;
recover datafile 8;
sql 'alter database datafile 9 online';
}
[oracle@dghost tmp]$ rman target / cmdfile=/tmp/re.sql
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Apr 9 22:30:56 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1461163151)
RMAN> run
2> {
3> sql 'alter database datafile 8 offline';
4> restore datafile 8;
5> recover datafile 8;
6> sql 'alter database datafile 8 online';
7> }
8>
using target database control file instead of recovery catalog
sql statement: alter database datafile 8 offline
Starting restore at 09-APR-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=150 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 00008 to /u01/oracle/oradata/orcl/examp01.dbf
channel ORA_DISK_1: reading from backup piece /tmp/0rs19lr3_1_1
channel ORA_DISK_1: piece handle=/tmp/0rs19lr3_1_1 tag=TAG20170409T221915
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 09-APR-17
Starting recover at 09-APR-17
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 09-APR-17
sql statement: alter database datafile 8 online
Recovery Manager complete.
5 检查数据师傅恢复成功
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.
Total System Global Area 584568832 bytes
Fixed Size 2230552 bytes
Variable Size 440403688 bytes
Database Buffers 134217728 bytes
Redo Buffers 7716864 bytes
Database mounted.
Database opened.
SQL> ho ls -l /u01/oracle/oradata/orcl
total 2117052
-rw-r----- 1 oracle dba 10240000 Apr 9 22:34 control01.ctl
-rw-r----- 1 oracle dba 10493952 Apr 9 22:33 examp01.dbf
-rw-r----- 1 oracle dba 52429312 Apr 9 22:33 redo01.log
-rw-r----- 1 oracle dba 52429312 Apr 9 22:33 redo02.log
-rw-r----- 1 oracle dba 52429312 Apr 9 22:34 redo03.log
-rw-r----- 1 oracle dba 650125312 Apr 9 22:33 sysaux01.dbf
-rw-r----- 1 oracle dba 1027612672 Apr 9 22:33 system01.dbf
-rw-r----- 1 oracle dba 275783680 Apr 9 21:56 temp1.dbf
-rw-r----- 1 oracle dba 10493952 Apr 9 22:33 tmpspace0327
-rw-r----- 1 oracle dba 10493952 Apr 9 22:33 undotbs02.dbf
-rw-r----- 1 oracle dba 10493952 Apr 9 22:33 user02.dbf
-rw-r----- 1 oracle dba 5251072 Apr 9 22:33 users01.dbf
数据文件恢复。