-bash-3.00$cd $ORACLE_HOME/rdbms/lib
-bash-3.00$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
-bash-3.00$ ./bbed Password:
BBED: Release 2.0.0.0.0 - Limited Production on Thu Dec 23 10:58:43 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED>
BBED> help all SET DBA [ dba | file#, block# ] SET FILENAME 'filename' SET FILE file# SET BLOCK [+/-]block# SET OFFSET [ [+/-]byte offset | symbol | *symbol ] SET BLOCKSIZE bytes SET LIST[FILE] 'filename' SET WIDTH character_count SET COUNT bytes_to_display SET IBASE [ HEX | OCT | DEC ] SET OBASE [ HEX | OCT | DEC ] SET MODE [ BROWSE | EDIT ] SET SPOOL [ Y | N ] SHOW [ | ALL ] INFO MAP[/v] [ DBA | FILENAME | FILE | BLOCK ] DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ] PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ] EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ] : N - a number which specifies a repeat count. u - a letter which specifies a unit size: b - b1, ub1 (byte) h - b2, ub2 (half-word) w - b4, ub4(word) r - Oracle table/index row f - a letter which specifies a display format: x - hexadecimal d - decimal u - unsigned decimal o - octal c - character (native) n - Oracle number t - Oracle date i - Oracle rowid FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ] COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ] MODIFY[/x|d|u|o|c] numeric/character string [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ] ASSIGN[/x|d|u|o] = : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ] : [ value | ] SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ] PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ] POP [ALL] REVERT [ DBA | FILE | FILENAME | BLOCK ] UNDO HELP [ | ALL ] VERIFY [ DBA | FILE | FILENAME | BLOCK ] CORRUPT [ DBA | FILE | FILENAME | BLOCK ]
BBED> exit
-bash-3.00$
还真不少,下面是几个常用的:
set 设定当前的环境。
show 查看当前的环境参数,跟sqlplus的同名命令类似。
dump 列出指定block的内容
find 在指定的block中查找指定的字符串,结果是显示出字符串,及其偏移量--offset,偏移量就是在block中的字节数
modify 修改指定block的指定偏移量的值,可以在线修改。
copy 把一个block的内容copy到另一个block中
verify 检查当前环境是否有坏块
sum 计算block的checksum,modify之后block就被标识为坏块,current checksum与reqired checksum不一致,sum命令可以计算出新的checksum并应用到当前块。
undo 回滚当前的修改操作,如果手误做错了,undo一下就ok了,回到原来的状态。
revert 回滚所有之前的修改操作,意思就是 undo all
bbed的默认的口令为blockedit
运行bbed之前先要自己写几个配置文件:
这里有2个 filelist.txt par.bbd
---filelist.txt中指定了具体数据文件,第一个域为编号,第二个域为数据文件全路径,第三个域为数据文件大小 -bash-3.00$ more filelist.txt
1 /u01/app/ora10g/oradata/aning/system01.dbf 608174080 2 /u01/app/ora10g/oradata/aning/undotbs01.dbf 52428800 3 /u01/app/ora10g/oradata/aning/sysaux01.dbf 293601280 4 /u01/app/ora10g/oradata/aning/users01.dbf 17039360 5 /u01/app/ora10g/oradata/aning/example01.dbf 104857600 6 /u01/app/ora10g/oradata/aning/test_part01.dbf 524288 7 /u01/app/ora10g/oradata/aning/test_part02.dbf 524288 8 /tmp/test_uniform.dbf 10485760 9 /u01/app/ora10g/oradata/aning/test_lmt_mssm.dbf 524288000 10 /u01/app/ora10g/oradata/aning/mssm.dbf 104857600 11 /u01/app/ora10g/oradata/aning/demo.dbf 52428800 12 /u01/app/ora10g/oradata/aning/testing.dbf 12582912 13 /u01/app/ora10g/oradata/aning/testingmssm.dbf 1048576 14 /u01/app/ora10g/oradata/aning/ts.dbf 1048576 15 /u01/app/ora10g/oradata/aning/system02.dbf 10485760
-bash-3.00$ more par.bbd blocksize=8192 listfile=filelist.txt mode=edit
编译好了就可以运行bbed了
下面做些实验
先建一个表插入一条数据
sqlplus / as sysdba
SQL> create table bbed(a varchar2(10)) tablespace users;
Table created.
SQL> insert into bbed values('aning');
1 row created.
SQL> commit;
Commit complete. SQL> select segment_name,file_id,block_id,blocks from dba_extents where segment_name='BBED';
SEGMENT_NAME FILE_ID BLOCK_ID BLOCKS ------------------------------ ---------- ---------- ---------- BBED 4 417 8
表存放在file4,block417 - 417+8,先关闭数据块对users数据文件做cp
SQL> shutdown immediate;
-bash-3.00$ cp /u01/app/ora10g/oradata/aning/users01.dbf /u01/app/ora10g/oradata/aning/users01.dbf.bak
SQL> startup ORACLE instance started.
Total System Global Area 285212672 bytes Fixed Size 1267068 bytes Variable Size 109054596 bytes Database Buffers 171966464 bytes Redo Buffers 2924544 bytes Database mounted. Database opened
重新启动数据块进入bbed
-bash-3.00$ pwd /home/oracle -bash-3.00$ bbed parfile=par.bbd
BBED> set file 4 FILE# 4
BBED> show FILE# 4 BLOCK# 1 OFFSET 0 DBA 0x01000001 (16777217 4,1) FILENAME /u01/app/ora10g/oradata/aning/users01.dbf BIFILE bifile.bbd LISTFILE filelist.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE log.bbd SPOOL No 刚才创建的bbed表在file4 block417 - 417+8上面,用bbed查看420上的数据
BBED> dump file 4 block 420 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 0 to 511 Dba:0x010001a4 ------------------------------------------------------------------------ 06a20000 a4010001 a67c1000 00000306 9aee0000 01000000 f1d00000 577c1000 00000000 02003200 a1010001 04001000 5c010000 13008000 92011f00 01200000 a67c1000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00010100 ffff1400 8f1f7b1f 7b1f0000 01008f1f 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 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 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> offset的偏移量是从0-511单位是字节,数据块是8k的,想看全部的可以扩大offset的范围
BBED> dump file 4 block 420 count 8200 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 0 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 06a20000 a4010001 a67c1000 00000306 9aee0000 01000000 f1d00000 577c1000 00000000 02003200 a1010001 04001000 5c010000 13008000 92011f00 01200000 a67c1000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00010100 ffff1400 8f1f7b1f 7b1f0000 01008f1f 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 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 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 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000002c 01010561 6e696e67 0306a67c
<32 bytes per line> Offsets: 0 to 8191 1024*8=8192个字节, 正好是8k,注意最后字节中有个61,这个就是表中的那条数据,验证一下:
SQL> select * from bbed;
A ---------- aning
SQL> select dump(a,1016) from bbed;
DUMP(A,1016) ------------------------------------------------------------------------------------------------------------------------------------------------------ Typ=1 Len=5 CharacterSet=ZHS16GBK: 61,6e,69,6e,67
字符a对应的16进制就是61,如果数据量大可以用find查找
BBED> help find FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]
BBED> set file 4 FILE# 4
BBED> set block 420 BLOCK# 420
BBED> find 97 curr File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 616e696e 670306a6 7c
<32 bytes per line>
BBED> find /x 61 curr File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 616e696e 670306a6 7c
<32 bytes per line>
在find之前要先设置file和block,默认是十进制的ascii编码,/x表示十六进制,find的结果显示出offset,即字符出现的位置
下面试验修改,把aning改成Oraning
SQL> select dump('Oraning',1016) from dual;
DUMP('ORANING',1016) -------------------------------------------------------- Typ=96 Len=7 CharacterSet=ZHS16GBK: 4f,72,61,6e,69,6e,67
BBED> help modify MODIFY[/x|d|u|o|c] numeric/character string [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
BBED> modify 98 file 4 block 420 offset 8183 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 626e696e 670306a6 7c
<32 bytes per line>
修改完之后61就变成62了,不过这时数据块是损坏状态,试验一下
BBED> verify DBVERIFY - Verification starting FILE = /u01/app/ora10g/oradata/aning/users01.dbf BLOCK = 420
Block 420 is corrupt Corrupt block relative dba: 0x010001a4 (file 0, block 420) Bad check value found during verification Data in bad block: type: 6 format: 2 rdba: 0x010001a4 last change scn: 0x0000.00107ca6 seq: 0x3 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0x7ca60603 check value in block header: 0xee9a computed block checksum: 0x300
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 : 1 Total Blocks Influx : 0
有一个块标识为坏块,从刚才备份的那个文件覆盖它
BBED> copy file 24 block 420 to file 4 block 420 Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 0 to 511 Dba:0x010001a4 ------------------------------------------------------------------------ 06a20000 a4010001 a67c1000 00000306 9aee0000 01000000 f1d00000 577c1000 00000000 02003200 a1010001 04001000 5c010000 13008000 92011f00 01200000 a67c1000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00010100 ffff1400 8f1f7b1f 7b1f0000 01008f1f 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 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 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>
从刚才关闭数据库cp的数据文件中复制第420块覆盖当前的块,覆盖了再检查一下
BBED> verify DBVERIFY - Verification starting FILE = /u01/app/ora10g/oradata/aning/users01.dbf BLOCK = 420
DBVERIFY - Verification complete
Total Blocks Examined : 1 Total Blocks Processed (Data) : 1 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
好了,看看8183的情况
BBED> dump file 4 block 420 offset 8183 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 616e696e 670306a6 7c
<32 bytes per line>
是61原来的字符a,再次改过来,看看回滚命令
BBED> modify /x 62 file 4 block 420 offset 8183 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 626e696e 670306a6 7c
<32 bytes per line>
BBED> undo BBED> modify /x 61 filename '/u01/app/ora10g/oradata/aning/users01.dbf' block 420. offset 8183. File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 616e696e 670306a6 7c
<32 bytes per line>
undo相当于sqlplus里面的rollback,不过是回滚上一步,而不是所有操作
下面试试revert,不过要重新登录,因为revert回滚这次登录以来的所有操作
BBED> exit
-bash-3.00$ bbed parfile=par.bbd Password:
BBED: Release 2.0.0.0.0 - Limited Production on Thu Dec 23 13:21:12 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> dump file 4 block 420 offset 8183 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 616e696e 670306a6 7c
<32 bytes per line>
BBED> modify /x 62 file 4 block 420 offset 8183 Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 626e696e 670306a6 7c
<32 bytes per line>
BBED> revert All changes made in this session will be rolled back. Proceed? (Y/N) y Reverted file '/u01/app/ora10g/oradata/aning/users01.dbf', block 420 Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
BBED> dump file 4 block 420 offset 8183 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 616e696e 670306a6 7c
<32 bytes per line>
BBED>
个人感觉bbed用在数据块恢复的时候,比如由于误操作把数据库的字典表的信息改错了,导致数据库不能启动了,此时用bbed在脱机的情况下把字典表的值再改回来。使数据库open。用modify改完数据之后,block处于corrupt状态,所以要通过sum命令计算并应用checksum值,使block状态恢复正常
BBED> dump file 4 block 420 offset 8183 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 616e696e 670306a6 7c
<32 bytes per line>
BBED> modify /x 62 file 4 block 420 offset 8183 File: /u01/app/ora10g/oradata/aning/users01.dbf (4) Block: 420 Offsets: 8183 to 8191 Dba:0x010001a4 ------------------------------------------------------------------------ 626e696e 670306a6 7c
<32 bytes per line>
BBED> verify DBVERIFY - Verification starting FILE = /u01/app/ora10g/oradata/aning/users01.dbf BLOCK = 420
Block 420 is corrupt Corrupt block relative dba: 0x010001a4 (file 0, block 420) Bad check value found during verification Data in bad block: type: 6 format: 2 rdba: 0x010001a4 last change scn: 0x0000.00107ca6 seq: 0x3 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0x7ca60603 check value in block header: 0xee9a computed block checksum: 0x300
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 : 1 Total Blocks Influx : 0
修改完之后block的状态是corrupt的。用sum命令使之有效。
BBED> help sum SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
BBED> sum file 4 block 420 Check value for File 4, Block 420: current = 0xee9a, required = 0xed9a
此时 current checksum 是0xee9a,required checksum 是 0xed9a
BBED> sum file 4 block 420 apply Check value for File 4, Block 420: current = 0xed9a, required = 0xed9a
加上apply参数,使checksum一致。此时block状态恢复正常。
BBED> verify DBVERIFY - Verification starting FILE = /u01/app/ora10g/oradata/aning/users01.dbf BLOCK = 420
DBVERIFY - Verification complete
Total Blocks Examined : 1 Total Blocks Processed (Data) : 1 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
看看数据库的数据
SQL> select * from bbed;
A ---------- aning
没变化,重启一下
SQL> startup force;
SQL> select * from bbed;
A ---------- bning
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12457158/viewspace-682593/
,如需转载,请注明出处,否则将追究法律责任。