[20161114]rman备份的疑问.txt

[20161114]rman备份的疑问.txt

--这个是我前几天做测试时遇到的疑问,不知道为什么rman 备份要修改数据块的dba地址。

1.环境:
SCOTT@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

CREATE TABLESPACE SUGAR DATAFILE
  '/mnt/ramdisk/book/sugar01.dbf' SIZE 40M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

create table t1 tablespace sugar as select rownum id ,to_char(rownum,'FM000000')||lpad('A',26,'A') name from dual connect by level<=1e5;
--建立大小5M的表。
create table t2 tablespace sugar as select rownum id ,to_char(rownum,'FM000000')||lpad('B',26,'B') name from dual connect by level<=2e5;
create table t3 tablespace sugar as select rownum id ,to_char(rownum,'FM000000')||lpad('C',26,'C') name from dual connect by level<=2e5;
alter system checkpoint;

2.备份数据文件6:
RMAN> backup datafile 6 format '/u01/backup/d6_1.bak' ;
Starting backup at 2016-11-11 17:02:48
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/mnt/ramdisk/book/sugar01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-11-11 17:02:49
channel ORA_DISK_1: finished piece 1 at 2016-11-11 17:02:50
piece handle=/u01/backup/d6_1.bak tag=TAG20161111T170248 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-11-11 17:02:50

$ strings -td /u01/backup/d6_1.bak| egrep '000996'
1125139 a 000996AAAAAAAAAAAAAAAAAAAAAAAAAA,
6146835 a 000996BBBBBBBBBBBBBBBBBBBBBBBBBB,
16132883 a 000996CCCCCCCCCCCCCCCCCCCCCCCCCC,

--1125139/8192=137.3460693359375
--6146835/8192=750.3460693359375
--16132883/8192=1969.3460693359375
--对应的信息在备份块中137,750,1969.

BBED> set filename '/u01/backup/d6_1.bak'
        FILENAME        /u01/backup/d6_1.bak

p block 137 kcbh.rdba_kcbh
p block 750 kcbh.rdba_kcbh
p block 1969 kcbh.rdba_kcbh

BBED> p block 137 kcbh.rdba_kcbh
ub4 rdba_kcbh                               @4        0x01800089

BBED> p block 750 kcbh.rdba_kcbh
ub4 rdba_kcbh                               @4        0x018003ee

BBED> p block 1969 kcbh.rdba_kcbh
ub4 rdba_kcbh                               @4        0x018008b1

BBED> set dba 0x01800089
        DBA             0x01800089 (25165961 6,137)

BBED> set dba 0x018003ee
        DBA             0x018003ee (25166830 6,1006)

BBED> set dba 0x018008b1
        DBA             0x018008b1 (25168049 6,2225)


SCOTT@book> column name format a32
SCOTT@book> select rowid,t1.id from t1 where name='000996AAAAAAAAAAAAAAAAAAAAAAAAAA';
ROWID                      ID
------------------ ----------
AAAVuXAAGAAAACIACF        996

SCOTT@book> @ &r/rowid AAAVuXAAGAAAACIACF
    OBJECT       FILE      BLOCK        ROW ROWID_DBA            DBA                  TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
     88983          6        136        133  0x1800088           6,136                alter system dump datafile 6 block 136 ;

SCOTT@book> select rowid,t2.* from t2 where name='000996BBBBBBBBBBBBBBBBBBBBBBBBBB';
ROWID                      ID NAME
------------------ ---------- --------------------------------
AAAVuYAAGAAAAMIACF        996 000996BBBBBBBBBBBBBBBBBBBBBBBBBB

SCOTT@book> @ &r/rowid AAAVuYAAGAAAAMIACF
    OBJECT       FILE      BLOCK        ROW ROWID_DBA            DBA                  TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
     88984          6        776        133  0x1800308           6,776                alter system dump datafile 6 block 776 ;

SCOTT@book> select rowid,t3.* from t3 where name='000996CCCCCCCCCCCCCCCCCCCCCCCCCC';
ROWID                      ID NAME
------------------ ---------- --------------------------------
AAAVuZAAGAAAAgIACF        996 000996CCCCCCCCCCCCCCCCCCCCCCCCCC

SCOTT@book> @ &r/rowid AAAVuZAAGAAAAgIACF
    OBJECT       FILE      BLOCK        ROW ROWID_DBA            DBA                  TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
     88985          6       2056        133  0x1800808           6,2056               alter system dump datafile 6 block 2056

--你可以发现备份是修改了dba地址。

BBED> set filename '/u01/backup/d6_1.bak'
        FILENAME        /u01/backup/d6_1.bak

BBED> x /rnc block 137  *kdbr[133]
rowdata[1519]                               @2829
-------------
flag@2829: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@2830: 0x00
cols@2831:    2

col    0[3] @2832: 996
col   1[32] @2836: 000996AAAAAAAAAAAAAAAAAAAAAAAAAA

BBED> x /rnc block 750  *kdbr[133]
rowdata[1519]                               @2829
-------------
flag@2829: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@2830: 0x00
cols@2831:    2

col    0[3] @2832: 996
col   1[32] @2836: 000996BBBBBBBBBBBBBBBBBBBBBBBBBB

BBED> x /rnc block 1969  *kdbr[133]
rowdata[1519]                               @2829
-------------
flag@2829: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@2830: 0x00
cols@2831:    2

col    0[3] @2832: 996
col   1[32] @2836: 000996CCCCCCCCCCCCCCCCCCCCCCCCCC

--//与数据块对比。
BBED> x /rnc dba 6,2056  *kdbr[133]
rowdata[1519]                               @2829
-------------
flag@2829: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@2830: 0x00
cols@2831:    2

col    0[3] @2832: 996
col   1[32] @2836: 000996CCCCCCCCCCCCCCCCCCCCCCCCCC

--你可以发现rman在备份时改变了dba地址,为什么?因为你改变dba地址,意味检查和也做了改变或者要重新计算。

3.单独保存对应数据块。

bvi -b 16842752 -s 8192 /mnt/ramdisk/book/sugar01.dbf   --//保存sugar2056.bin
bvi -b 16130048 -s 8192 /u01/backup/d6_1.bak            --//保存bak1969.bin

$ xxd -c 16 sugar2056.bin > aa1
$ xxd -c 16 bak1969.bin   > aa2

$ diff -Nur aa1 aa2
--- aa1 2016-11-11 17:36:44.000000000 +0800
+++ aa2 2016-11-11 17:36:51.000000000 +0800
@@ -1,5 +1,5 @@
-0000000: 06a2 0000 0808 8001 a883 6000 0000 0204  ..........`.....
-0000010: 6406 0000 0100 0000 995b 0100 a183 6000  d........[....`.
+0000000: 06a2 0000 b108 8001 a883 6000 0000 0204  ..........`.....
                    ~~~~~~~~~
+0000010: d606 0100 0100 0000 995b 0100 a183 6000  ?.......[....`.
          ~~~~~~~~~
0000020: 0000 0000 0300 3201 0008 8001 ffff 0000  ......2.....??..
0000030: 0000 0000 0000 0000 0000 0000 0080 0000  ................
0000040: a183 6000 0000 0000 0000 0000 0000 0000  ..`.............
@@ -509,4 +509,4 @@
0001fc0: 4343 4343 4343 4343 4343 4343 4343 4343  CCCCCCCCCCCCCCCC
0001fd0: 4343 4343 2c00 0203 c209 4020 3030 3038  CCCC,...?@ 0008
0001fe0: 3633 4343 4343 4343 4343 4343 4343 4343  63CCCCCCCCCCCCCC
-0001ff0: 4343 4343 4343 4343 4343 4343 0206 a883  CCCCCCCCCCCC....
+0001ff0: 4343 4343 4343 4343 4343 4343 0806 a883  CCCCCCCCCCCC....
                                        ~~~~
--注意看~的地方。
--b108 8001 是rdba_kcbh dba地址。
--d606      是 chkval_kcbh 检查和
--0100      是 spare3_kcbh
-- 0806 a883是 tailchk

5.比较备份与数据文件中的kcbh.spare3_kcbh

BBED> p dba 6,136  kcbh.spare3_kcbh
ub2 spare3_kcbh                             @18       0x0000

BBED> p dba 6,776  kcbh.spare3_kcbh
ub2 spare3_kcbh                             @18       0x0000

BBED> p dba 6,2056 kcbh.spare3_kcbh
ub2 spare3_kcbh                             @18       0x0000

BBED> p filename '/u01/backup/d6_1.bak' block 137 kcbh.spare3_kcbh
ub2 spare3_kcbh                             @18       0x0001

BBED> p filename '/u01/backup/d6_1.bak' block 750 kcbh.spare3_kcbh
ub2 spare3_kcbh                             @18       0x0001

BBED> p filename '/u01/backup/d6_1.bak' block 1969 kcbh.spare3_kcbh
ub2 spare3_kcbh                             @18       0x0001

-- 你可以发现备份修改kcbh.spare3_kcbh=0x0001.

6.比较备份与数据文件中的tailchk.

BBED> p dba 6,136  tailchk
ub4 tailchk                                 @8188     0x83290602

BBED> p dba 6,776  tailchk
ub4 tailchk                                 @8188     0x83640602

BBED> p dba 6,2056  tailchk
ub4 tailchk                                 @8188     0x83a80602

BBED> p filename '/u01/backup/d6_1.bak' block 137 tailchk
ub4 tailchk                                 @8188     0x83290688

BBED> p filename '/u01/backup/d6_1.bak' block 750 tailchk
ub4 tailchk                                 @8188     0x83640608

BBED> p filename '/u01/backup/d6_1.bak' block 1969 tailchk
ub4 tailchk                                 @8188     0x83a80608

--前4位,对应块提交的scn低4位,没有变动。后面2位数据文件都是0x02, 而备份不同还真看出来如何还原。

7.回来看看备份与数据文件中的rdba_kcbh。
BBED> p dba 6,136  rdba_kcbh
ub4 rdba_kcbh                               @4        0x01800088

BBED> p dba 6,776  rdba_kcbh
ub4 rdba_kcbh                               @4        0x01800308

BBED> p dba 6,2056  rdba_kcbh
ub4 rdba_kcbh                               @4        0x01800808

BBED> p filename '/u01/backup/d6_1.bak' block 137 rdba_kcbh
ub4 rdba_kcbh                               @4        0x01800089

BBED> p filename '/u01/backup/d6_1.bak' block 750 rdba_kcbh
ub4 rdba_kcbh                               @4        0x018003ee

BBED> p filename '/u01/backup/d6_1.bak' block 1969 rdba_kcbh
ub4 rdba_kcbh                               @4        0x018008b1

--做一个推测tailchk的低2位实际上是真实数据块的rdba_kcbh的低2位。

BBED> p filename '/u01/backup/d6_1.bak' block 137 rdba_kcbh
ub4 rdba_kcbh                               @4        0x01800089

--备份的rdba_kcbh低2位是0x89,替换尾部0x88,变成0x01800088
BBED> set dba 0x01800088
        DBA             0x01800088 (25165960 6,136)
--这样对应相应的数据块。

8.反向推测看看(随便找一个块看看):

BBED> p filename '/u01/backup/d6_1.bak' block 770 rdba_kcbh
ub4 rdba_kcbh                               @4        0x01800382

BBED> p filename '/u01/backup/d6_1.bak' block 770 tailchk
ub4 tailchk                                 @8188     0x8368061c

BBED> p filename '/u01/backup/d6_1.bak' block 770 spare3_kcbh
ub2 spare3_kcbh                             @18       0x0001

--可以推出这个备份块对应的数据块dba是0x0180031c

BBED> set dba 0x0180031c
        DBA             0x0180031c (25166620 6,796)

--验证看看:
BBED> x /rnc dba 0x0180031c  *kdbr[133]
rowdata[1519]                               @2829
-------------
flag@2829: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@2830: 0x00
cols@2831:    2

col    0[3] @2832: 4264
col   1[32] @2836: 004264BBBBBBBBBBBBBBBBBBBBBBBBBB

BBED> x /rnc filename '/u01/backup/d6_1.bak' block 770 *kdbr[133]
rowdata[1519]                               @2829
-------------
flag@2829: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@2830: 0x00
cols@2831:    2

col    0[3] @2832: 4264
col   1[32] @2836: 004264BBBBBBBBBBBBBBBBBBBBBBBBBB

--你可以发现备份与数据块信息对应。

--以上都是我的猜测,也许不对。为什么oracle的rman备份要这样设置,那位知道...........

上一篇:Akamai 发布互联网安全报告:DDoS 攻击量激增


下一篇:XML封装与验证消息