[20160405]bbed修改文件头.txt

[20160405]bbed修改文件头.txt

--以前做过一次,重复测试:
http://blog.itpub.net/267265/viewspace-746222/

如果数据库数据文件损坏,并且archivelog损坏,这样无法完全恢复,如果仅仅某个数据文件的scn与其他文件不同步,导致该数据文件无法mount.
正常可以像odu之类的工具恢复.但是在实际上如果修改数据文件的scn保持同步,这样数据库可以正常打开,选择常规的方法imp/exp以及expdp/impdp
方式恢复,这样虽然丢失一部分数据,至少一定程度减少损失.

--以前测试有点乱.

1.环境:
--冷备份数据库:

$ cp tea01.dbf tea01.dbf_ORG

 

SYS@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name BOOK

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    770      SYSTEM               ***     /mnt/ramdisk/book/system01.dbf
2    1580     SYSAUX               ***     /mnt/ramdisk/book/sysaux01.dbf
3    1435     UNDOTBS1             ***     /mnt/ramdisk/book/undotbs01.dbf
4    500      USERS                ***     /mnt/ramdisk/book/users01.dbf
5    346      EXAMPLE              ***     /mnt/ramdisk/book/example01.dbf
6    100      SUGAR                ***     /mnt/ramdisk/book/sugar01.dbf
7    1        TEA                  ***     /mnt/ramdisk/book/tea01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    400      TEMP                 32767       /mnt/ramdisk/book/temp01.dbf

SYS@book> select * from scott.empx where rownum<=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 YYYY       CLERK           7902 1980-12-17 00:00:00        800                    20

SYS@book> update scott.empx set ename='ZZZZ' where EMPNO=7369;
1 row updated.

SYS@book> commit ;
Commit complete.

alter system archive log current ;
/
/
/

2.假设现在数据库破坏,tea文件仅仅存在旧的备份,看看是否online看看.
SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

$ cp tea01.dbf tea01.dbf_0405
$ mv tea01.dbf_ORG tea01.dbf

--模拟归档丢失.
$ cd /u01/app/oracle/archivelog/
$ mv book book.xxx
$ mkdir book

3.测试:

SYS@book> startup
ORACLE instance started.

Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'

--都是归档,无法恢复.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                             TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ----------------
    1        13227502431 2016-04-05 11:33:18                7       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/system01.dbf   SYSTEM
    2        13227502431 2016-04-05 11:33:18             1834       13227286650 ONLINE              1004 NO  /mnt/ramdisk/book/sysaux01.dbf   SYSAUX
    3        13227502431 2016-04-05 11:33:18           923328       13227286650 ONLINE               924 NO  /mnt/ramdisk/book/undotbs01.dbf  UNDOTBS1
    4        13227502431 2016-04-05 11:33:18            16143       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/users01.dbf    USERS
    5        13227502431 2016-04-05 11:33:18           952916       13227286650 ONLINE               921 NO  /mnt/ramdisk/book/example01.dbf  EXAMPLE
    6        13227502431 2016-04-05 11:33:18          1314508       13227286650 ONLINE               937 NO  /mnt/ramdisk/book/sugar01.dbf    SUGAR
    7        13227500866 2016-03-31 08:53:17      13227207527       13227286650 ONLINE                25 NO  /mnt/ramdisk/book/tea01.dbf      TEA
7 rows selected.

SYS@book> @ &r/10to16 13227502431
10 to 16 HEX   REVERSE16
-------------- -----------------------------------
00003146bab5f 0x5fab6b14-03000000

SYS@book> @ &r/10to16 13227500866
10 to 16 HEX   REVERSE16
-------------- -----------------------------------
00003146ba542 0x42a56b14-03000000

BBED> p kcvfh.kcvfhckp.kcvcpscn.kscnbas dba 7,1
ub4 kscnbas                                 @484      0x146ba542

BBED> p kcvfh.kcvfhckp.kcvcpscn.kscnbas dba 1,1
ub4 kscnbas                                 @484      0x146bab5f

BBED> assign dba 7,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas = dba 1,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas;
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
ub4 kscnbas                                 @484      0x146bab5f

BBED> sum apply dba 7.1
BBED-00205: illegal or out of range DBA (File 0, Block 7)

BBED> sum apply dba 7,1
Check value for File 7, Block 1:
current = 0x0b12, required = 0x0b12

BBED> verify dba 7,1
DBVERIFY - Verification starting
FILE = /mnt/ramdisk/book/tea01.dbf
BLOCK = 1

DBVERIFY - Verification complete

Total Blocks Examined         : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing   (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing   (Index): 0
Total Blocks Empty            : 0
Total Blocks Marked Corrupt   : 0
Total Blocks Influx           : 0
Message 531 not found;  product=RDBMS; facility=BBED

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                             TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ---------------
    1        13227502431 2016-04-05 11:33:18                7       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/system01.dbf   SYSTEM
    2        13227502431 2016-04-05 11:33:18             1834       13227286650 ONLINE              1004 NO  /mnt/ramdisk/book/sysaux01.dbf   SYSAUX
    3        13227502431 2016-04-05 11:33:18           923328       13227286650 ONLINE               924 NO  /mnt/ramdisk/book/undotbs01.dbf  UNDOTBS1
    4        13227502431 2016-04-05 11:33:18            16143       13227286650 ONLINE              1008 NO  /mnt/ramdisk/book/users01.dbf    USERS
    5        13227502431 2016-04-05 11:33:18           952916       13227286650 ONLINE               921 NO  /mnt/ramdisk/book/example01.dbf  EXAMPLE
    6        13227502431 2016-04-05 11:33:18          1314508       13227286650 ONLINE               937 NO  /mnt/ramdisk/book/sugar01.dbf    SUGAR
    7        13227502431 2016-03-31 08:53:17      13227207527       13227286650 ONLINE                25 NO  /mnt/ramdisk/book/tea01.dbf      TEA
7 rows selected.

SYS@book> alter database open ;
alter database open
*
ERROR at line 1:
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'

SYS@book> recover datafile 7 ;
Media recovery complete.
SYS@book> alter database open ;
Database altered.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                            TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- ------------------------------- ---------------
    1        13227502434 2016-04-05 11:43:01                7       13227286650 ONLINE              1009 YES /mnt/ramdisk/book/system01.dbf  SYSTEM
    2        13227502434 2016-04-05 11:43:01             1834       13227286650 ONLINE              1005 YES /mnt/ramdisk/book/sysaux01.dbf  SYSAUX
    3        13227502434 2016-04-05 11:43:01           923328       13227286650 ONLINE               925 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1
    4        13227502434 2016-04-05 11:43:01            16143       13227286650 ONLINE              1009 YES /mnt/ramdisk/book/users01.dbf   USERS
    5        13227502434 2016-04-05 11:43:01           952916       13227286650 ONLINE               922 YES /mnt/ramdisk/book/example01.dbf EXAMPLE
    6        13227502434 2016-04-05 11:43:01          1314508       13227286650 ONLINE               938 YES /mnt/ramdisk/book/sugar01.dbf   SUGAR
    7        13227502434 2016-04-05 11:43:01      13227207527       13227286650 ONLINE                32 YES /mnt/ramdisk/book/tea01.dbf     TEA
7 rows selected.

--自动修复CHECKPOINT_COUNT记数.视乎11.2.0.4不再需要修改CHECKPOINT_COUNT.

SYS@book> select * from scott.empx where rownum<=1;
       EMPNO ENAME      JOB                MGR HIREDATE                     SAL         COMM       DEPTNO
------------ ---------- --------- ------------ ------------------- ------------ ------------ ------------
        7369 YYYY       CLERK             7902 1980-12-17 00:00:00          800                        20

--不过修改都丢失了.还原:
$ mv tea01.dbf_0405 tea01.dbf
$ cd /u01/app/oracle/archivelog/
$ mv book book.test
$ mv book.xxx/ book

SYS@book> startup mount
ORACLE instance started.
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
SYS@book> alter database open ;
alter database open
*
ERROR at line 1:
ORA-01113: file 7 needs media recovery
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'

SYS@book> recover datafile 7 ;
Media recovery complete.
SYS@book> alter database open ;

Database altered.

SYS@book> select * from scott.empx where rownum<=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 ZZZZ       CLERK           7902 1980-12-17 00:00:00        800                    20

--OK,已经还原了.

--CHECKPOINT_COUNT的位置:

BBED> p kcvfh.kcvfhcpc dba 7,1
ub4 kcvfhcpc                                @140      0x00000023

BBED> p kcvfh.kcvfhcpc dba 1,1
ub4 kcvfhcpc                                @140      0x000003f3

SYS@book> @ &r/16to10 3f3
16 to 10 DEC
------------
        1011

SYS@book> @ &r/16to10 23
16 to 10 DEC
------------
          35

 

--实际上这样的测试存在许多问题,比如drop表,create表,这样在系统表空间存在定义,而数据文件已经丢失了.

时间: 2024-10-30 14:02:25

[20160405]bbed修改文件头.txt的相关文章

[20160407]bbed修改文件头2(补充).txt

[20160407]bbed修改文件头2(补充).txt --昨天被别人问一个问题,就是我的测试修改数据文件相应的CHECKPOINT_CHANGE#就ok了.偏移量是block=1的offset=484. --链接 http://blog.itpub.net/267265/viewspace-2075424/ --不过别人问的是这个时间是如何存储的.我以前也做过一些.链接: --http://blog.itpub.net/267265/viewspace-746222/ --我的感觉在11.2

[20160405]bbed的assign命令.txt

[20160405]bbed的assign命令.txt --我记得开始学习bbed的时候,看的是一份pdf文档,提到assign的用法,摘要如下: assign The assign command does symbolic assignment, with type and range checking. Either target or source can be omitted for the current offset.  For example, the following com

【BBED】 SYSTEM文件头损坏的恢复(4)

[BBED] SYSTEM文件头损坏的恢复   1.1  BLOG文档结构图     1.2  前言部分   1.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ① BBED恢复SYSTEM文件头 ② BBED查看文件头的信息     Tips:        ① 若文章代码格式有错乱,推荐使用QQ.搜狗或360浏览器,也可以下载pdf格式的文档来查看,pdf文档下载地址:http://yunpan.cn/cd

[20160405]利用bbed修改跳过损坏的索引.txt

[20160405]利用bbed修改跳过损坏的索引.txt --oracle的启动通过system的第一块的rdba(kcvfhrdb) http://blog.itpub.net/267265/viewspace-2016219/ http://blog.itpub.net/267265/viewspace-2022857/ --如果前obj#<=59对象损坏,不允许重建,假设某个索引损坏,是否可以跳过索引启动数据库呢?自己做一个测试. --以sys.undo$的索引i_undo1为例做测试:

[20161111]数据库文件头的修复.txt

[20161111]数据库文件头的修复.txt --这里指文件头实际上数据文件第1块(从0算起). --找到一个链接,http://www.cnblogs.com/hrhguanli/p/4708273.html --要修改的信息相对较多. 1 .改动数据的DBA,rdba_kcbh 2 .改动文件的大小,kccfhfsz 3 .改动文件号,kccfhfno 4 .改动文件创建时SCN,kcvfhcrs 5 .改动文件创建时间,kcvfhcrt 6 .改动表空间号,kcvfhtsn 7 .改动相

如何使用BBED查看SYSTEM文件头的root dba及bootstrap$

数据库版本11.2.0.4 实验思路是:     --其中数据库OPEN时的TRACE信息,可以参考:http://blog.csdn.net/q947817003/article/details/17025489 file#1 block#1==>root dba==>struct ktetb 即先从SYSTEM的数据文件头:file#1 block#1 找到root dba的位置,然后在root dba所在的块内,找到struct ktetb 所描述的块的位置,然后查看struct kte

[20160526]bbed修改数据记录(不等长).txt

[20160526]bbed修改数据记录(不等长).txt --以前做的测试,有点乱,当时没有很好的理解快速提交.而且做的很乱,链接如下: http://blog.itpub.net/267265/viewspace-1193074/ --今天重复测试看看: 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ ------

[20160413利用bbed修改跳过损坏的索引.txt

[20160413利用bbed修改跳过损坏的索引.txt --前一阵子做过利用bbed修改跳过损坏的索引,这次测试看看破坏索引SYS.I_OBJ1看看. 1.环境: SYS@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- ----------------------------------------------

[20140624]bbed修改数据记录(不等长).txt

[20140624]bbed修改数据记录(不等长).txt http://www.itpub.net/thread-1872851-1-1.html --给出的问题修改记录时,长度没有变化,如果存在变化,修改与原来的不同,要修改kdbr[0]的值. --还有一些细节的步骤. SCOTT@test> @ver BANNER -------------------------------------------------------------------------------- Oracle