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


1 创建备份

RMAN> backup database plus archivelog;  

2 搭建环境

  1. hr@ORCL> create table tt (name varchar2(20));  
  2.   
  3. Table created.  
  4.   
  5. hr@ORCL> insert into tt values('test1');  
  6.   
  7. 1 row created.  
  8.   
  9. hr@ORCL> insert into tt values('test2');  
  10.   
  11. 1 row created.  
  12.   
  13. hr@ORCL> insert into tt values('test3');  
  14.   
  15. 1 row created.  
  16.   
  17. hr@ORCL> commit;  
  18.   
  19. Commit complete.  
  20.   
  21. hr@ORCL> select * from tt;  
  22.   
  23. NAME  
  24. --------------------   
  25. test1  
  26. test2  
  27. test3  

3 模拟数据文件丢失

  1. sys@ORCL> select default_tablespace from dba_users where username='HR';  
  2.   
  3. DEFAULT_TABLESPACE  
  4. --------    
  5. users  
  6.   
  7. sys@ORCL> select dt.tablespace_name,  
  8.   2              file_id,  
  9.   3              file_name  
  10.   4         from dba_tablespaces dt, dba_data_files dd  
  11.   5        where dt.tablespace_name=dd.tablespace_name;  
  12.   
  13. TABLESPA    FILE_ID FILE_NAME  
  14. -------- ---------- ----------------------------------------------------------------------   
  15. USERS             4 /u01/app/Oracle/oradata/ORCL/datafile/o1_mf_users_8050fkdh_.dbf  
  16. SYSAUX            3 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_sysaux_8050fk3w_.dbf  
  17. UNDOTBS1          2 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_8050fkc6_.dbf  
  18. SYSTEM            1 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_8050fk2z_.dbf  
  19. EXAMPLE           5 /u01/app/oracle/oradata/ORCL/datafile/o1_mf_example_8050jhm7_.dbf  
  20. UNDOTBS2          6 /u01/app/oracle/oradata/ORCL/datafile/undotbsthi.dbf  
  21. RMANTBS           7 /u01/app/oracle/flash_recovery_area/ORCL/rmantbs01.dbf  
  22.   
  23. sys@ORCL> shutdown immediate;  
  24. Database closed.  
  25. Database dismounted.  
  26. ORACLE instance shut down.  
  27.   
  28. sys@ORCL> host rm -rf /u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_8050fkdh_.dbf;  
  29.   
  30. 重新启动数据库:  
  31. sys@ORCL> startup  
  32. ORACLE instance started.  
  33.   
  34. Total System Global Area  419430400 bytes  
  35. Fixed Size                  1219760 bytes  
  36. Variable Size             121635664 bytes  
  37. Database Buffers          293601280 bytes  
  38. Redo Buffers                2973696 bytes  
  39. Database mounted.  
  40. ORA-01157: cannot identify/lock data file 4 - see DBWR trace file  
  41. ORA-01110: data file 4: '/u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_8050fkdh_.dbf' 

4 用rman执行修复和恢复

  1. [oracle@localhost ~]$ rman target /  
  2.   
  3. Recovery Manager: Release 10.2.0.1.0 - Production on Mon Aug 6 22:54:36 2012  
  4.   
  5. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
  6.   
  7. connected to target database: ORCL (DBID=1316499950, not open)  
  8.   
  9. RMAN> restore datafile 4;  
  10.   
  11. Starting restore at 06-AUG-12  
  12. using target database control file instead of recovery catalog  
  13. allocated channel: ORA_DISK_1  
  14. channel ORA_DISK_1: sid=155 devtype=DISK  
  15.   
  16. channel ORA_DISK_1: starting datafile backupset restore  
  17. channel ORA_DISK_1: specifying datafile(s) to restore from backup set  
  18. restoring datafile 00004 to /u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_8050fkdh_.dbf  
  19. 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  
  20. channel ORA_DISK_1: restored backup piece 1  
  21. piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2012_08_06/o1_mf_nnndf_TAG20120806T223510_81zojyz5_.bkp tag=TAG20120806T223510  
  22. channel ORA_DISK_1: restore complete, elapsed time: 00:00:03  
  23. Finished restore at 06-AUG-12  
  24.   
  25. RMAN> recover datafile 4;  
  26.   
  27. Starting recover at 06-AUG-12  
  28. using channel ORA_DISK_1  
  29.   
  30. starting media recovery  
  31. media recovery complete, elapsed time: 00:00:03  
  32.   
  33. Finished recover at 06-AUG-12  
  34.   
  35. RMAN> alter database open;  
  36.   
  37. database opened  

5 查询数据

  1. hr@ORCL> select * from tt;  
  2.   
  3. NAME  
  4. --------------------   
  5. test1  
  6. test2  
  7. test3  

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

 

相关内容