利用BBED修改資料塊SCN----極端環境下的資料恢復

wolfreturn發表於2015-05-19


破壞system表空間檔案  ----比較暴力做前需做好備份
cd $ORACLE_BASE/oradata/PROD1

cp system01.dbf system01.dbf.bak
切日誌模擬生產交易,更新SCN

SYS@PROD1 > alter system switch logfile;
多切幾次
SYS@PROD1 > /

System altered.

SYS@PROD1 > /

System altered.

把舊的system檔案直接複製替換掉新的

cp system01.dbf.bak system01.dbf

再次切日誌模擬生產交易
SYS@PROD1 > alter system switch logfile;
多切幾次
SYS@PROD1 > /

System altered.

SYS@PROD1 > /

System altered.
/
alter system switch logfile
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 25597
Session ID: 24 Serial number: 887
出現問題,資料庫直接宕掉

SYS@PROD1 > ERROR:
ORA-03114: not connected to ORACLE


SYS@PROD1 > conn / as sysdba
Connected.
SYS@PROD1 > select status from v$instance;
ERROR:
ORA-01012: not logged on

SYS@PROD1 > conn / as sysdba


SYS@PROD1 > startup
ORACLE instance started.

Total System Global Area 313860096 bytes
Fixed Size 1344652 bytes
Variable Size 260049780 bytes
Database Buffers 46137344 bytes
Redo Buffers 6328320 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/app/oracle/oradata/PROD1/system01.dbf'


SYS@PROD1 > col name for a50
SYS@PROD1 > select name,checkpoint_change# from v$datafile;

NAME CHECKPOINT_CHANGE#
-------------------------------------------------- ------------------
/u01/app/oracle/oradata/PROD1/system01.dbf 1199315
/u01/app/oracle/oradata/PROD1/sysaux01.dbf 1199315
/u01/app/oracle/oradata/PROD1/undotbs01.dbf 1199315
/u01/app/oracle/oradata/PROD1/users01.dbf 1199315
/u01/app/oracle/oradata/PROD1/example01.dbf 1199315


scn轉換成16進位制
SYS@PROD1 > select to_char(1199315,'xxxxxxxx') from dual;


TO_CHAR(1
---------
124cd3



SYS@PROD1 > select name,checkpoint_change# from v$datafile_header;

NAME CHECKPOINT_CHANGE#
-------------------------------------------------- ------------------
/u01/app/oracle/oradata/PROD1/system01.dbf 1191817
/u01/app/oracle/oradata/PROD1/sysaux01.dbf 1199315
/u01/app/oracle/oradata/PROD1/undotbs01.dbf 1199315
/u01/app/oracle/oradata/PROD1/users01.dbf 1199315
/u01/app/oracle/oradata/PROD1/example01.dbf 1199315


可以看到資料庫users01.dbf的scn點為1191817明顯是用的備份的資料檔案。oracle在open資料庫時要對控制檔案,資料檔案頭的scn進行檢查,一致才能開啟,所以這裡我們透過ddeb來修改資料檔案頭讓它和其他的資料檔案的scn相同,達到起庫的目的。



[oracle@guo ~]$ bbed parfile=bbed.par
Password:

BBED: Release 2.0.0.0.0 - Limited Production on Tue May 19 10:52:04 2015

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

************* !!! For Oracle Internal Use only !!! ***************

用bbed查詢bbed01資料檔案結構資訊
BBED> set dba 1,1
DBA 0x00400001 (4194305 1,1)

Bbed檢視kcvfh資訊
BBED> p kcvfhckp
struct kcvfhckp, 36 bytes @484
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 0x00122f89
ub2 kscnwrp @488 0x0000
ub4 kcvcptim @492 0x34754da5
ub2 kcvcpthr @496 0x0001
union u, 12 bytes @500
struct kcvcprba, 12 bytes @500
ub4 kcrbaseq @500 0x0000001e
ub4 kcrbabno @504 0x00000002
ub2 kcrbabof @508 0x0010
ub1 kcvcpetb[0] @512 0x02
ub1 kcvcpetb[1] @513 0x00
ub1 kcvcpetb[2] @514 0x00
ub1 kcvcpetb[3] @515 0x00
ub1 kcvcpetb[4] @516 0x00
ub1 kcvcpetb[5] @517 0x00
ub1 kcvcpetb[6] @518 0x00
ub1 kcvcpetb[7] @519 0x00



BBED> set filename '/u01/app/oracle/oradata/PROD1/system01.dbf'
FILENAME /u01/app/oracle/oradata/PROD1/system01.dbf

BBED> p kcvfhckp
struct kcvfhckp, 36 bytes @484
struct kcvcpscn, 8 bytes @484
ub4 kscnbas @484 0x00122f89
ub2 kscnwrp @488 0x0000
ub4 kcvcptim @492 0x34754da5
ub2 kcvcpthr @496 0x0001
union u, 12 bytes @500
struct kcvcprba, 12 bytes @500
ub4 kcrbaseq @500 0x0000001e
ub4 kcrbabno @504 0x00000002
ub2 kcrbabof @508 0x0010
ub1 kcvcpetb[0] @512 0x02
ub1 kcvcpetb[1] @513 0x00
ub1 kcvcpetb[2] @514 0x00
ub1 kcvcpetb[3] @515 0x00
ub1 kcvcpetb[4] @516 0x00
ub1 kcvcpetb[5] @517 0x00
ub1 kcvcpetb[6] @518 0x00
ub1 kcvcpetb[7] @519 0x00
檢視正常資料檔案頭
BBED> d /v dba 4,1 offset 484
File: /u01/app/oracle/oradata/PROD1/users01.dbf (4)
Block: 1 Offsets: 484 to 995 Dba:0x01000001
-------------------------------------------------------
d34c1200 0000ae31 c9607534 0100af31 l ?L....?1?`u4..?1
29000000 02000000 10000000 02000000 l )...............
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
0a000a00 0a000100 00000000 00000000 l ................
00000000 02000001 03000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................

<16 bytes per line>
system檔案頭
BBED> d /v dba 1,1 offset 484
File: /u01/app/oracle/oradata/PROD1/system01.dbf (1)
Block: 1 Offsets: 484 to 995 Dba:0x00400001
-------------------------------------------------------
892f1200 000089bf a54d7534 01000000 l ./.....??Mu4....
1e000000 02000000 10000000 02000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
0a000a00 0a000100 00000000 00000000 l ................
00000000 02004000 72fc0b00 00000000 l ......@.r?......
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 024c6582 l .............Le.
d61636a4 7acf3f5d 13b1e763 d0000000 l ?.6?z??].??c?...
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00173356 l ..............3V
1c4cd306 46040f87 3704db71 a6210600 l .L?.F...7.?q?!..
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................

<16 bytes per line>
修改system檔案頭
BBED> modify /x d34c1200 dba 1,1 offset 484
BBED-00209: invalid number (d34c1200)


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

BBED> d /v dba 1,1 offset 484
File: /u01/app/oracle/oradata/PROD1/system01.dbf (1)
Block: 1 Offsets: 484 to 995 Dba:0x00400001
-------------------------------------------------------
892f1200 000089bf a54d7534 01000000 l ./.....??Mu4....
1e000000 02000000 10000000 02000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
0a000a00 0a000100 00000000 00000000 l ................
00000000 02004000 72fc0b00 00000000 l ......@.r?......
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 024c6582 l .............Le.
d61636a4 7acf3f5d 13b1e763 d0000000 l ?.6?z??].??c?...
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00173356 l ..............3V
1c4cd306 46040f87 3704db71 a6210600 l .L?.F...7.?q?!..
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................

<16 bytes per line>

BBED> modify /x d34c1200 dba 1,1 offset 484
BBED-00209: invalid number (d34c1200)


BBED> modify /x d34c1200 dba 1,1 offset 484
BBED-00209: invalid number (d34c1200)


BBED> d /v dba 2,1 offset 484
File: /u01/app/oracle/oradata/PROD1/sysaux01.dbf (2)
Block: 1 Offsets: 484 to 995 Dba:0x00800001
-------------------------------------------------------
d34c1200 0000ae31 c9607534 0100af31 l ?L....?1?`u4..?1
29000000 02000000 10000000 02000000 l )...............
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
0a000a00 0a000100 00000000 00000000 l ................
00000000 02008000 5c040c00 00000000 l ........\.......
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................

<16 bytes per line>



BBED> modify /x d34c1200 dba 1,1 offset 484
BBED-00209: invalid number (d34c1200)


完整16進位制提示無效d34c1200,不知道為什麼
BBED> modify /x d34c dba 1,1 offset 484  (填寫部分,字母前的)
File: /u01/app/oracle/oradata/PROD1/system01.dbf (1)
Block: 1 Offsets: 484 to 995 Dba:0x00400001
------------------------------------------------------------------------
d34c1200 000089bf a54d7534 01000000 1e000000 02000000 10000000 02000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
0a000a00 0a000100 00000000 00000000 00000000 02004000 72fc0b00 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 024c6582 d61636a4 7acf3f5d 13b1e763 d0000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00173356
1c4cd306 46040f87 3704db71 a6210600 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

<32 bytes per line>

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

BBED> d /v dba 1,1 offset 484
File: /u01/app/oracle/oradata/PROD1/system01.dbf (1)
Block: 1 Offsets: 484 to 995 Dba:0x00400001
-------------------------------------------------------
d34c1200 000089bf a54d7534 01000000 l ?L.....??Mu4....
1e000000 02000000 10000000 02000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
0a000a00 0a000100 00000000 00000000 l ................
00000000 02004000 72fc0b00 00000000 l ......@.r?......
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 024c6582 l .............Le.
d61636a4 7acf3f5d 13b1e763 d0000000 l ?.6?z??].??c?...
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00173356 l ..............3V
1c4cd306 46040f87 3704db71 a6210600 l .L?.F...7.?q?!..
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................
00000000 00000000 00000000 00000000 l ................

<16 bytes per line>

BBED>


SYS@PROD1 > 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'


SYS@PROD1 > recover database;
Media recovery complete.
SYS@PROD1 > alter database open;

Database altered.

















來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24742969/viewspace-1662201/,如需轉載,請註明出處,否則將追究法律責任。

相關文章