控制文件丢失通过rman备份恢复

控制文件完全丢失后进行恢复
    今天做了个实验,模拟控制文件完全丢失后,通过rman备份来进行还原。

实验环境:
    操作系统环境:
  1. [oracle@REDHAT6 tmp]$ lsb_release -a
  2. 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
  3. Distributor ID:    OracleServer
  4. Description:    Oracle Linux Server release 6.5
  5. Release:    6.5
  6. Codename:    n/a
    数据库环境:
  1. SQL> select * from v$version;

  2. BANNER
  3. --------------------------------------------------------------------------------
  4. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
  5. PL/SQL Release 11.2.0.3.0 - Production
  6. CORE    11.2.0.3.0    Production
  7. TNS for Linux: Version 11.2.0.3.0 - Production
  8. NLSRTL Version 11.2.0.3.0 - Production

  9. SQL> show parameter control_files;

  10. NAME                 TYPE        VALUE
  11. -------------------- ----------- ------------------------------
  12. control_files        string      /u01/app/oradata/ORCL/control01.ctl
    这里为了实验方便,所以控制文件只设置了一份。

1. 备份数据库

  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)


  2. RMAN> backup database format '/home/oracle/db_backup/%U.bak';

  3. RMAN> list backup;

  4. List of Backup Sets
  5. ===================

  6. BS Key Type LV Size Device Type Elapsed Time Completion Time
  7. ------- ---- -- ---------- ----------- ------------ ---------------
  8. 21 Full 1.32G DISK 00:01:44 20-MAY-15
  9.         BP Key: 21 Status: AVAILABLE Compressed: NO Tag: TAG20150520T110508
  10.         Piece Name: /home/oracle/db_backup/0rq7df35_1_1.bak
  11.   List of Datafiles in backup set 21
  12.   File LV Type Ckp SCN Ckp Time Name
  13.   ---- -- ---- ---------- --------- ----
  14.   1 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/system01.dbf
  15.   2 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/sysaux01.dbf
  16.   3 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/undotbs01.dbf
  17.   4 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/users01.dbf
  18.   5 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/example01.dbf
  19.   6 Full 3149096 20-MAY-15 /u01/app/oradata/ORCL/df1.dbf
  20.   7 Full 3149096 20-MAY-15 /u01/app/oradata/df2.dbfdf2
  21.   8 Full 3149096 20-MAY-15 /u01/app/oradata/rman1.dbf

  22. BS Key Type LV Size Device Type Elapsed Time Completion Time
  23. ------- ---- -- ---------- ----------- ------------ ---------------
  24. 22 Full 9.39M DISK 00:00:01 20-MAY-15
  25.         BP Key: 22 Status: AVAILABLE Compressed: NO Tag: TAG20150520T110508
  26.         Piece Name: /home/oracle/db_backup/0sq7df6f_1_1.bak
  27.   SPFILE Included: Modification time: 20-MAY-15
  28.   SPFILE db_unique_name: ORCL
  29.   Control File Included: Ckp SCN: 3149581 Ckp time: 20-MAY-15
    数据文件备份在:/home/oracle/db_backup/0rq7df35_1_1.bak,
    控制文件和参数文件备份在:/home/oracle/db_backup/0sq7df6f_1_1.bak,
   注意上面的 “ DBID=1396675707 ” ,这个在后面控制文件恢复时会用到的

2. 模拟控制文件丢失
    1) 将控制文件重重命名
  1. [oracle@REDHAT6 ORCL]$ pwd
  2. /u01/app/oradata/ORCL
  3. [oracle@REDHAT6 ORCL]$ mv control01.ctl control01_bak.ctl
    2) 重启数据库
  1. SQL> startup force;
  2. ORACLE instance started.

  3. Total System Global Area 889389056 bytes
  4. Fixed Size         2233480 bytes
  5. Variable Size         494930808 bytes
  6. Database Buffers     385875968 bytes
  7. Redo Buffers         6348800 bytes
  8. ORA-00205: error in identifying control file, check alert log for more info
    这里控制文件已经报错了,无法指定控制文件

3. 恢复控制文件
    1) 将数据库启动到nomount状态     
  1. SQL> startup nomount;
  2. ORACLE instance started.

  3. Total System Global Area 889389056 bytes
  4. Fixed Size         2233480 bytes
  5. Variable Size         494930808 bytes
  6. Database Buffers     385875968 bytes
  7. Redo Buffers         6348800 bytes
    2) 通过rman还原控制文件
  1. [oracle@REDHAT6 ORCL]$ rman target /

  2. Recovery Manager: Release 11.2.0.3.0 - Production on Wed May 20 11:27:37 2015

  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

  4. connected to target database: ORCL (not mounted)

  5. RMAN> set DBID=1396675707

  6. executing command: SET DBID

  7. RMAN> restore controlfile from '/home/oracle/db_backup/0sq7df6f_1_1.bak';

  8. Starting restore at 20-MAY-15
  9. using target database control file instead of recovery catalog
  10. allocated channel: ORA_DISK_1
  11. channel ORA_DISK_1: SID=134 device type=DISK

  12. channel ORA_DISK_1: restoring control file
  13. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
  14. output file name=/u01/app/oradata/ORCL/control01.ctl
  15. Finished restore at 20-MAY-15
    由于数据库是nomount状态,所以rman连接进来的时候,ORCL (not mounted)。
    这里有两点需要注意下,
    首先,rman连接进来后,DBID是未知的,要先执行 RMAN> set DBID=1396675707 (DBID的值在上面rman备份时是有的),
    其次,还原的备份集要正确,在进行rman备份时,通过 list backup 可以看到控制文件所在的备份集。

4. 恢复数据库
    1)  将数据库启动到mount状态
  1. SQL> alter database mount
    2) 还原数据库,  恢复数据库 和 启动数据库
  1. RMAN> restore database;

  2. Starting restore at 20-MAY-15
  3. Starting implicit crosscheck backup at 20-MAY-15
  4. using target database control file instead of recovery catalog
  5. allocated channel: ORA_DISK_1
  6. channel ORA_DISK_1: SID=125 device type=DISK
  7. Crosschecked 1 objects
  8. Finished implicit crosscheck backup at 20-MAY-15

  9. Starting implicit crosscheck copy at 20-MAY-15
  10. using channel ORA_DISK_1
  11. Finished implicit crosscheck copy at 20-MAY-15

  12. searching for all files in the recovery area
  13. cataloging files...
  14. no files cataloged

  15. using channel ORA_DISK_1

  16. channel ORA_DISK_1: starting datafile backup set restore
  17. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  18. channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oradata/ORCL/system01.dbf
  19. channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oradata/ORCL/sysaux01.dbf
  20. channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oradata/ORCL/undotbs01.dbf
  21. channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oradata/ORCL/users01.dbf
  22. channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oradata/ORCL/example01.dbf
  23. channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oradata/ORCL/df1.dbf
  24. channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oradata/df2.dbfdf2
  25. channel ORA_DISK_1: restoring datafile 00008 to /u01/app/oradata/rman1.dbf
  26. channel ORA_DISK_1: reading from backup piece /home/oracle/db_backup/0uq7dmht_1_1
  27. channel ORA_DISK_1: piece handle=/home/oracle/db_backup/0uq7dmht_1_1 tag=TAG20150520T131228
  28. channel ORA_DISK_1: restored backup piece 1
  29. channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
  30. Finished restore at 20-MAY-15

  31. RMAN> recover database;

  32. Starting recover at 20-MAY-15
  33. using channel ORA_DISK_1

  34. starting media recovery

  35. archived log for thread 1 with sequence 1 is already on disk as file /u01/app/oradata/ORCL/redo01.log
  36. archived log file name=/u01/app/oradata/ORCL/redo01.log thread=1 sequence=1
  37. media recovery complete, elapsed time: 00:00:01
  38. Finished recover at 20-MAY-15

  39. RMAN> sql 'alter database open resetlogs';

  40. sql statement: alter database open resetlogs

现在数据库已经正常启动了!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30150152/viewspace-1664021/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30150152/viewspace-1664021/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值