`
sjk2013
  • 浏览: 2174096 次
文章分类
社区版块
存档分类
最新评论

rman实验之归档模式有备份,正常关机丢失数据文件的恢复

 
阅读更多

1 创建备份

RMAN> backup database plus archivelog;


2 搭建环境

hr@ORCL> create table tt (name varchar2(20));

Table created.

hr@ORCL> insert into tt values('test1');

1 row created.

hr@ORCL> insert into tt values('test2');

1 row created.

hr@ORCL> insert into tt values('test3');

1 row created.

hr@ORCL> commit;

Commit complete.

hr@ORCL> select * from tt;

NAME
--------------------
test1
test2
test3


3 模拟数据文件丢失

sys@ORCL> select default_tablespace from dba_users where username='HR';

DEFAULT_TABLESPACE
-------- 
users

sys@ORCL> select dt.tablespace_name,
  2              file_id,
  3              file_name
  4         from dba_tablespaces dt, dba_data_files dd
  5        where dt.tablespace_name=dd.tablespace_name;

TABLESPA    FILE_ID FILE_NAME
-------- ---------- ----------------------------------------------------------------------
USERS             4 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_8050fkdh_.dbf
SYSAUX            3 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_sysaux_8050fk3w_.dbf
UNDOTBS1          2 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_8050fkc6_.dbf
SYSTEM            1 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_8050fk2z_.dbf
EXAMPLE           5 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_example_8050jhm7_.dbf
UNDOTBS2          6 /u01/app/oracle/oradata/ORCL/datafile/undotbsthi.dbf
RMANTBS           7 /u01/app/oracle/flash_recovery_area/ORCL/rmantbs01.dbf

sys@ORCL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

sys@ORCL> host rm -rf /u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_8050fkdh_.dbf;

重新启动数据库:
sys@ORCL> startup
ORACLE instance started.

Total System Global Area  419430400 bytes
Fixed Size                  1219760 bytes
Variable Size             121635664 bytes
Database Buffers          293601280 bytes
Redo Buffers                2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_8050fkdh_.dbf'


4 用rman执行修复和恢复

[oracle@localhost ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Mon Aug 6 22:54:36 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: ORCL (DBID=1316499950, not open)

RMAN> restore datafile 4;

Starting restore at 06-AUG-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_8050fkdh_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2012_08_06/o1_mf_nnndf_TAG20120806T223510_81zojyz5_.bkp
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2012_08_06/o1_mf_nnndf_TAG20120806T223510_81zojyz5_.bkp tag=TAG20120806T223510
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 06-AUG-12

RMAN> recover datafile 4;

Starting recover at 06-AUG-12
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 06-AUG-12

RMAN> alter database open;

database opened


5 查询数据

hr@ORCL> select * from tt;

NAME
--------------------
test1
test2
test3


数据全部回来,恢复成功!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics