主题:一则简单的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元数据的简单实验的更多相关文章

  1. 【练习】trace文本重建控制文件

    这个小练习是针对控制文件全部丢失后怎么能快速的重建一个控制文件,快速的起库 1.备份控制文件到trace下 SQL> alter database backup controlfile to t ...

  2. Oracle DB备份恢复篇之丢失控制文件

    实验目的 本篇主要模拟控制文件丢失后,如何根据实际情况恢复数据库,才能使数据库尽可能不丢失数据. 实验环境 1)Linux系统环境 [oracle@DG1 ~]$ lsb_release -a LSB ...

  3. Oracle 控制文件(CONTROLFILE)

    一.Oracle 控制文件 为二进制文件,初始化大小由CREATE DATABASE指定,可以使用RMAN备份 记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息等 ...

  4. Oracle 物理结构(四) 文件-控制文件

    一.什么是控制文件 控制文件是Oracle数据库中十分重要的文件.Oracle启动时,首先会读取参数文件,读取了参数文件,实例所需要的共享内存和后台进程就可以启动了,这就是数据库实例的nomunt阶段 ...

  5. 用备份控制文件做不完全恢复下的完全恢复(数据文件备份<旧>--新建表空间--控制文件备份<次新>--日志归档文件<新>)

    为什么会使用备份的控制文件? 实际工作中主要有两种情况:第一种:当前控制文件全部损坏,而数据文件备份,控制文件备份及当前日志处于不同SCN版本,它们之间又增加过表空间(数据文件).第二种:当前控制文件 ...

  6. Oracle删除控制文件恢复

    控制文件被删除后,系统崩溃,下面介绍下如何恢复控制文件 SQL> conn / as sysdbaConnected to an idle instance.SQL> startup no ...

  7. 【RMAN】Oracle中如何备份控制文件?备份控制文件的方式有哪几种?

    真题1. 如何备份控制文件?备份控制文件的方式有哪几种? 答案:备份控制文件的方式有多种. ① 备份控制文件可以在线进行: SQL> ALTER DATABASE BACKUP CONTROLF ...

  8. oracle控制文件问题

    下午时连接数据库突然发现连不上了,监听报错找不到服务,于是登录数据库所在服务器,查看监听状态,oracle:lsnrctl status 监听状态正常,登入数据库查看[oracle@frkdb1 ~] ...

  9. RMAN兼容性、控制文件自动备份、保存时间、备份策略、备份脚本(二)

    RMAN 程序的兼容性 RMAN 环境由以下5部分组成:(1) RMAN executable(2) Recovery catalog database(3) Recovery catalog sch ...

随机推荐

  1. win10创建本地用户

    win+r,输入lusrmgr.msc win+i

  2. Redis入门-02-CentOS7环境搭建

    CentOS7下redis安装过程,安装后需要开启端口号6379 #下载 wget http://download.redis.io/releases/redis-3.2.4.tar.gz #解压 t ...

  3. B-S 期权定价模型

    Black-Scholes 期权定价模型概述 1997年10月10日,第二十九届诺贝尔经济学奖授予了两位美国学者,哈佛商学院教授罗伯特·默顿(RoBert Merton)和斯坦福大学教授迈伦·斯克尔斯 ...

  4. EntityManager的Clear方法的使用

    在日常开发中,如果使用hibernate的话,常常会被hibernate的事务搞得焦头烂额.今天解决了之前项目中一直存在的问题,记录一下. 问题描述 有一张表TemplateCopy,如下 publi ...

  5. gulp常用插件之gulp-rev-collector使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-rev-collector这是一款根据gulp-rev生成的manifest.json文件中的映射, 去替换文件名称, 也可以替换路径. ...

  6. 浅谈C#委托的用法-delegate[转]

    一.委托的概念 委托和类一样是一种用户自定义类型,它存储的就是一系列具有相同签名和返回类型的方法的地址,调用委托的时候,它所包含的所有方法都会被执行. 借用百度上的一句话概括:委托是一个类,它定义了方 ...

  7. 初入python

    初入python 一定要学好python 求1-100的和: i=1 s=0 while i<101: s=s+i i=i+1 print(s)

  8. FZU-Problem 2150 Fire Game(两点bfs)

    Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns) ...

  9. docker的个人理解

    一.什么是docker? docker就是集装箱的原理.可以实现远超于虚拟机的轻量级虚拟化.它是内核级的虚拟化.期望达到使项目运行环境一次封装,到处运行的目的. 集装箱解决了什么问题?在一艘大船上,可 ...

  10. Mybatis的解析和运行原理

    Mybatis的解析和运行原理 Mybatis的运行过程大致分为两大步:第一步,读取配置文件缓存到Configuration对象,用以创建 SqlSessionFactory:第二步,SqlSessi ...