暂无图片
暂无图片
3
暂无图片
暂无图片
暂无图片

BBED的学习测试--跳过归档恢复数据文件

原创 张玉龙 2022-05-08
872

本文档仅限测试使用,对于生产环境,非专业人士请谨慎使用BBED,对数据保持敬畏之心。

测试环境

-- 归档模式 alter system set log_archive_dest_1='location=/u01/app/oracle/archive'; shutdown immediate startup mount alter database archivelog; alter database open; -- 创建测试表空间 create tablespace test datafile '/u01/app/oracle/oradata/ORCLT/test02.dbf' size 50M; -- 创建测试用户 create user test identified by test default tablespace test; grant connect,resource to test; grant unlimited tablespace to test; -- 创建测试表 create table test.tt(id int,name varchar2(10)); insert into test.tt values(1,'aa'); commit; -- 查看数据文件的 FILE# SQL> col name for a60 select * from v$dbfile; FILE# NAME CON_ID ---------- ------------------------------------------------------------ ---------- 7 /u01/app/oracle/oradata/ORCLT/users01.dbf 0 4 /u01/app/oracle/oradata/ORCLT/undotbs01.dbf 0 1 /u01/app/oracle/oradata/ORCLT/system01.dbf 0 3 /u01/app/oracle/oradata/ORCLT/sysaux01.dbf 0 5 /u01/app/oracle/oradata/ORCLT/test02.dbf 0 -- 对5号文件做RMAN备份 RMAN> backup datafile 5 format '/home/oracle/rmanbak/dbfile_5_%U'; -- 插入数据,切换归档日志 SQL> select sequence#,status,name from v$archived_log; SEQUENCE# S NAME ---------- - ------------------------------------------------------------ 13 A /u01/app/oracle/archive/1_13_1103926869.dbf SQL> insert into test.tt values(2,'bb'); SQL> commit; SQL> alter system switch logfile; SQL> alter system switch logfile; SQL> alter system switch logfile; SQL> insert into test.tt values(3,'cc'); SQL> commit; SQL> alter system switch logfile; SQL> select sequence#,status,name from v$archived_log; SEQUENCE# S NAME ---------- - ------------------------------------------------------------ 13 A /u01/app/oracle/archive/1_13_1103926869.dbf 14 A /u01/app/oracle/archive/1_14_1103926869.dbf -- (2,'bb') 15 A /u01/app/oracle/archive/1_15_1103926869.dbf 16 A /u01/app/oracle/archive/1_16_1103926869.dbf 17 A /u01/app/oracle/archive/1_17_1103926869.dbf -- (3,'cc') 9 rows selected. -- 删除归档日志文件 [oracle@ora11g ~]$ mv /u01/app/oracle/archive/1_14_1103926869.dbf /u01/app/oracle/archive/1_14_1103926869.dbf.bak [oracle@ora11g ~]$ mv /u01/app/oracle/archive/1_15_1103926869.dbf /u01/app/oracle/archive/1_15_1103926869.dbf.bak -- 5号文件离线 SQL> select file#,CREATION_CHANGE#,CHECKPOINT_CHANGE# ,UNRECOVERABLE_CHANGE#,LAST_CHANGE#,OFFLINE_CHANGE#,STATUS from v$datafile order by 1; FILE# CREATION_CHANGE# CHECKPOINT_CHANGE# UNRECOVERABLE_CHANGE# LAST_CHANGE# OFFLINE_CHANGE# STATUS ---------- ---------------- ------------------ --------------------- ------------ --------------- ------- 1 9 2406481 0 1920976 SYSTEM 3 5480 2406481 0 1920976 ONLINE 4 1920446 2406481 0 1920976 ONLINE 5 2403673 2406481 0 0 ONLINE 7 32876 2406481 0 1920976 ONLINE SQL> alter database datafile 5 offline; SQL> select file#,CREATION_CHANGE#,CHECKPOINT_CHANGE# ,UNRECOVERABLE_CHANGE#,LAST_CHANGE#,OFFLINE_CHANGE#,STATUS from v$datafile order by 1; FILE# CREATION_CHANGE# CHECKPOINT_CHANGE# UNRECOVERABLE_CHANGE# LAST_CHANGE# OFFLINE_CHANGE# STATUS ---------- ---------------- ------------------ --------------------- ------------ --------------- ------- 1 9 2406481 0 1920976 SYSTEM 3 5480 2406481 0 1920976 ONLINE 4 1920446 2406481 0 1920976 ONLINE 5 2403673 2406481 0 2406766 0 RECOVER 7 32876 2406481 0 1920976 ONLINE --归档模式下,当数据文件offline时,其对应的数据文件头 stop scn 会更新,同时 controlfile 中该 datafile 的stop scn信息也会更新,此时也会更新offline scn,并且offline scn等于stop scn. -- 对5号文件进行还原 RMAN> restore datafile 5; -- 5号数据文件无法被Online SQL> alter database datafile 5 online; alter database datafile 5 online * ERROR at line 1: ORA-01113: file 5 needs media recovery ORA-01110: data file 5: '/u01/app/oracle/oradata/ORCLT/test02.dbf' -- 对5号文件进行恢复 RMAN> recover datafile 5; Starting recover at 06-MAY-22 using channel ORA_DISK_1 starting media recovery archived log for thread 1 with sequence 16 is already on disk as file /u01/app/oracle/archive/1_16_1103926869.dbf archived log for thread 1 with sequence 17 is already on disk as file /u01/app/oracle/archive/1_17_1103926869.dbf RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 05/06/2022 21:38:57 RMAN-06053: unable to perform media recovery because of missing log RMAN-06025: no backup of archived log for thread 1 with sequence 15 and starting SCN of 2406462 found to restore RMAN-06025: no backup of archived log for thread 1 with sequence 14 and starting SCN of 2406432 found to restore

恢复

查出介质复恢的检查点

SQL> select to_char(SEQUENCE#,'xxxxxxxxxxxxxxxxxx') SEQUENCE,to_char(FIRST_CHANGE#,'xxxxxxxxxxxxxxxxxxxxxxxx') FIRST_CHANGE from v$archived_log where sequence#=16; SEQUENCE FIRST_CHANGE ------------------- ------------------------- 10 24b842

修改文件头检查点 kscnbas 和 kcrbaseq

BBED> info File# Name Size(blks) ----- ---- ---------- 1 /u01/app/oracle/oradata/ORCLT/system01.dbf 116480 3 /u01/app/oracle/oradata/ORCLT/sysaux01.dbf 74240 4 /u01/app/oracle/oradata/ORCLT/undotbs01.dbf 44160 5 /u01/app/oracle/oradata/ORCLT/test02.dbf 6400 7 /u01/app/oracle/oradata/ORCLT/users01.dbf 640 BBED> p kcvfhckp struct kcvfhckp, 36 bytes @484 struct kcvcpscn, 8 bytes @484 ub4 kscnbas @484 0x0024b820 union u, 12 bytes @500 struct kcvcprba, 12 bytes @500 ub4 kcrbaseq @500 0x0000000e BBED> modify /x 42b82400 offset 484 BBED> modify /x 10 offset 500 BBED> p kcvfhckp struct kcvfhckp, 36 bytes @484 struct kcvcpscn, 8 bytes @484 ub4 kscnbas @484 0x0024b842 union u, 12 bytes @500 struct kcvcprba, 12 bytes @500 ub4 kcrbaseq @500 0x00000010 BBED> sum apply

恢复和online数据文件

SQL> recover datafile 5; Media recovery complete. SQL> alter database datafile 5 online; Database altered. -- 查看数据,被跳过的归档里面的数据不在了 SQL> select * from test.tt; ID NAME ---------- ------------------------------------------------------------ 1 aa 3 cc
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论