码迷,mamicode.com
首页 > 其他好文 > 详细

一则关于控制文件全部丢失后如何重新编目RMAN元数据的简单实验

时间:2019-05-22 14:08:40      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:应用归档   bytes   var   dbi   自动   www   off   lob   size   

主题:一则简单的RMAN元数据编目实验,来自于博客园AskScuti

场景:RMAN备份完整情况下,未使用Catalog目录库。删除了所有的控制文件,在手工重建后,导致记录在控制文件中的RMAN备份元数据丢失。

目录

1. RMAN备份

2. 删除所有控制文件

3. 重建控制文件

4. 重新编目元数据

5. 验证可用性

 

1. RMAN备份

更改RMAN控制文件自动全备选项(建议开启)

RMAN> show all;

using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name PROD1 are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO %F; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM AES128; # default
CONFIGURE COMPRESSION ALGORITHM BASIC AS OF RELEASE DEFAULT OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO /u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_PROD1.f; # default

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

RMAN进行全备

RMAN> backup database format /u01/app/oracle/backup/%U_%s_%d.full.bak;

Starting backup at 2019-05-22 12:34:33
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 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=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf
input datafile file number=00010 name=/u01/app/oracle/oradata/PROD1/aaa02.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/PROD1/tbs_c01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/PROD1/aaa01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD1/abc01.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/PROD1/abcd01.dbf
channel ORA_DISK_1: starting piece 1 at 2019-05-22 12:34:34
channel ORA_DISK_1: finished piece 1 at 2019-05-22 12:35:11
piece handle=/u01/app/oracle/backup/01u26b2p_1_1_1_PROD1.full.bak tag=TAG20190522T123433 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:38
Finished backup at 2019-05-22 12:35:12

Starting Control File and SPFILE Autobackup at 2019-05-22 12:35:12
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2019_05_22/o1_mf_s_1008938112_gg9nd0oc_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2019-05-22 12:35:13

查看RMAN备份集

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size  Device Type Elapsed Time Completion Time    
------- ---- -- ----- ----------- ------------ -------------------
1       Full    1.70G DISK        00:00:37     2019-05-22 12:35:10
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20190522T123433
        Piece Name: /u01/app/oracle/backup/01u26b2p_1_1_1_PROD1.full.bak
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/system01.dbf
  2       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/sysaux01.dbf
  3       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/undotbs01.dbf
  4       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/users01.dbf
  5       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/example01.dbf
  6       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/abc01.dbf
  7       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/abcd01.dbf
  8       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/tbs_c01.dbf
  9       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/aaa01.dbf
  10      Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/aaa02.dbf

BS Key  Type LV Size  Device Type Elapsed Time Completion Time    
------- ---- -- ----- ----------- ------------ -------------------
2       Full    9.36M DISK        00:00:00     2019-05-22 12:35:12
        BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20190522T123512
        Piece Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2019_05_22/o1_mf_s_1008938112_gg9nd0oc_.bkp
  SPFILE Included: Modification time: 2019-05-22 11:54:09
  SPFILE db_unique_name: PROD1
  Control File Included: Ckp SCN: 1757737      Ckp time: 2019-05-22 12:35:12

 

2. 删除所有控制文件

删除当前系统所有控制文件

SQL> select name from v$controlfile;

NAME
-----------------------------------------------------
/u01/app/oracle/oradata/PROD1/control01.ctl
/u01/app/oracle/oradata/PROD1/control02.ctl
/u01/app/oracle/oradata/PROD1/control03.ctl
/u01/app/oracle/oradata/PROD1/control04.ctl
/u01/app/oracle/oradata/PROD1/control05.ctl
/u01/app/oracle/oradata/PROD1/control06.ctl
/u01/app/oracle/oradata/PROD1/control07.ctl
/u01/app/oracle/oradata/PROD1/control08.ctl

8 rows selected.

SQL> !rm -rf /u01/app/oracle/oradata/PROD1/*.ctl

SQL> startup force;
ORACLE instance started.

Total System Global Area  830930944 bytes
Fixed Size               2232920 bytes
Variable Size            591400360 bytes
Database Buffers         234881024 bytes
Redo Buffers              2416640 bytes
ORA-00205: error in identifying control file, check alert log for more info

 

3. 重建控制文件

重启失败,手工重建控制文件。重建前,请确认好所有数据文件、日志文件具体路径。如果之前没有单独备份控制文件,可参考官方文档11g Release 2 (11.2) Database Backup and Recovery User‘s Guide:To create a new control file and recover the database 语句进行重建。

手工编写脚本

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "PROD1" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 /u01/app/oracle/oradata/PROD1/redo01.log  SIZE 50M BLOCKSIZE 512,
  GROUP 2 /u01/app/oracle/oradata/PROD1/redo02.log  SIZE 50M BLOCKSIZE 512,
  GROUP 3 /u01/app/oracle/oradata/PROD1/redo03.log  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  /u01/app/oracle/oradata/PROD1/system01.dbf,
  /u01/app/oracle/oradata/PROD1/sysaux01.dbf,
  /u01/app/oracle/oradata/PROD1/undotbs01.dbf,
  /u01/app/oracle/oradata/PROD1/users01.dbf,
  /u01/app/oracle/oradata/PROD1/example01.dbf,
  /u01/app/oracle/oradata/PROD1/abc01.dbf,
  /u01/app/oracle/oradata/PROD1/abcd01.dbf,
  /u01/app/oracle/oradata/PROD1/tbs_c01.dbf,
  /u01/app/oracle/oradata/PROD1/aaa01.dbf,
  /u01/app/oracle/oradata/PROD1/aaa02.dbf
CHARACTER SET AL32UTF8
;

运行脚本

SQL> shutdown abort;
ORACLE instance shut down.
SQL> @con.sql

Control file created.

注意:控制文件会根据参数文件里面指定的具体路径被重新创建,但是,因为SCN号与数据文件不同,所以无法直接打开,也就是需要恢复Recover。

直接打开会报错

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: /u01/app/oracle/oradata/PROD1/system01.dbf

动态性能视图 v$recover_file 里面记录了需要恢复的所有数据文件

SQL> select * from v$recover_file;

进行恢复:由于控制文件被重建,所以恢复必须使用 using backup controlfile 语句进行恢复,且必须以 resetlogs 方式打开数据库。

SQL> recover database using backup controlfile;
ORA-00279: change 1757718 generated at 05/22/2019 12:34:34 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive1/1_67_1001001677.dbf
ORA-00280: change 1757718 for thread 1 is in sequence #67


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log /u01/app/oracle/archive1/1_67_1001001677.dbf
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


ORA-00308: cannot open archived log /u01/app/oracle/archive1/1_67_1001001677.dbf
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

这时候自动应用归档的时候提示错误,是因为,没有此归档(没有生成),介质恢复需要用的数据应该在日志文件里面,尝试下

SQL> recover database using backup controlfile;
ORA-00279: change 1757718 generated at 05/22/2019 12:34:34 needed for thread 1
ORA-00289: suggestion : /u01/app/oracle/archive1/1_67_1001001677.dbf
ORA-00280: change 1757718 for thread 1 is in sequence #67


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/oradata/PROD1/redo01.log
Log applied.
Media recovery complete.

证明需要恢复的数据是在 redo01.dbf 在线日志文件中,因此完成了恢复。

最后,以 resetlogs 方式打开数据库

SQL> alter database open resetlogs;

Database altered.

4. 重新编目元数据

此时连接 RMAN ,运行命令 list backup; 是没有任何元数据信息的。因为之前存在控制文件中,但是由于被删除,后手工重建,所以元数据丢失。

[oracle@henry ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Wed May 22 13:05:02 2019

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

connected to target database: PROD1 (DBID=2222344843)

RMAN> list backup;

using target database control file instead of recovery catalog
specification does not match any backup in the repository

接下来,找到之前RMAN的备份片,进行重新编目(手工注册)

RMAN> catalog backuppiece /u01/app/oracle/backup/01u26b2p_1_1_1_PROD1.full.bak;

cataloged backup piece
backup piece handle=/u01/app/oracle/backup/01u26b2p_1_1_1_PROD1.full.bak RECID=1 STAMP=1008940142

RMAN> catalog backuppiece /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2019_05_22/o1_mf_s_1008938112_gg9nd0oc_.bkp;

cataloged backup piece
backup piece handle=/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2019_05_22/o1_mf_s_1008938112_gg9nd0oc_.bkp RECID=2 STAMP=1008940181

这时候,再次运行 list backup;命令即可显示

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size  Device Type Elapsed Time Completion Time    
------- ---- -- ----- ----------- ------------ -------------------
1       Full    1.70G DISK        00:00:00     2019-05-22 12:34:33
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20190522T123433
        Piece Name: /u01/app/oracle/backup/01u26b2p_1_1_1_PROD1.full.bak
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  1       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/system01.dbf
  2       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/sysaux01.dbf
  3       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/undotbs01.dbf
  4       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/users01.dbf
  5       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/example01.dbf
  6       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/abc01.dbf
  7       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/abcd01.dbf
  8       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/tbs_c01.dbf
  9       Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/aaa01.dbf
  10      Full 1757718    2019-05-22 12:34:34 /u01/app/oracle/oradata/PROD1/aaa02.dbf

BS Key  Type LV Size  Device Type Elapsed Time Completion Time    
------- ---- -- ----- ----------- ------------ -------------------
2       Full    9.36M DISK        00:00:00     2019-05-22 12:35:12
        BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20190522T123512
        Piece Name: /u01/app/oracle/fast_recovery_area/PROD1/autobackup/2019_05_22/o1_mf_s_1008938112_gg9nd0oc_.bkp
  SPFILE Included: Modification time: 2019-05-22 11:54:09
  SPFILE db_unique_name: PROD1
  Control File Included: Ckp SCN: 1757737      Ckp time: 2019-05-22 12:35:12

5. 验证可用性

验证下可用性,手工直接删除某数据文件,并重启

SQL> select name from v$datafile;

NAME
--------------------------------------------------
/u01/app/oracle/oradata/PROD1/system01.dbf
/u01/app/oracle/oradata/PROD1/sysaux01.dbf
/u01/app/oracle/oradata/PROD1/undotbs01.dbf
/u01/app/oracle/oradata/PROD1/users01.dbf
/u01/app/oracle/oradata/PROD1/example01.dbf
/u01/app/oracle/oradata/PROD1/abc01.dbf
/u01/app/oracle/oradata/PROD1/abcd01.dbf
/u01/app/oracle/oradata/PROD1/tbs_c01.dbf
/u01/app/oracle/oradata/PROD1/aaa01.dbf
/u01/app/oracle/oradata/PROD1/aaa02.dbf

10 rows selected.

SQL> !rm -rf /u01/app/oracle/oradata/PROD1/abc01.dbf

SQL> startup force;
ORACLE instance started.

Total System Global Area  830930944 bytes
Fixed Size            2232920 bytes
Variable Size          591400360 bytes
Database Buffers      234881024 bytes
Redo Buffers            2416640 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 6 - see DBWR trace file
ORA-01110: data file 6: /u01/app/oracle/oradata/PROD1/abc01.dbf

报错后,通过RMAN进行6号文件的还原与恢复

[oracle@henry ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Wed May 22 13:11:18 2019

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

connected to target database: PROD1 (DBID=2222344843, not open)

RMAN> restore datafile 6;

Starting restore at 2019-05-22 13:11:40
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 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 00006 to /u01/app/oracle/oradata/PROD1/abc01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/backup/01u26b2p_1_1_1_PROD1.full.bak
channel ORA_DISK_1: piece handle=/u01/app/oracle/backup/01u26b2p_1_1_1_PROD1.full.bak tag=TAG20190522T123433
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2019-05-22 13:11:42

RMAN> recover datafile 6;

Starting recover at 2019-05-22 13:11:49
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 67 is already on disk as file /u01/app/oracle/archive1/1_67_1001001677.dbf
archived log file name=/u01/app/oracle/archive1/1_67_1001001677.dbf thread=1 sequence=67
media recovery complete, elapsed time: 00:00:00
Finished recover at 2019-05-22 13:11:49

一则关于控制文件全部丢失后如何重新编目RMAN元数据的简单实验

标签:应用归档   bytes   var   dbi   自动   www   off   lob   size   

原文地址:https://www.cnblogs.com/askscuti/p/10905449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!