1

我不想等待 Oracle DataDumpexpdb完成对转储文件的写入。所以我从创建的那一刻开始读取数据。然后我将此数据写入另一个文件。

它工作正常 - 文件大小相同(OracleDump 创建的文件和我的数据监控脚本创建的文件)。

但是当我运行 cmp 时,它显示了 27 个字节的差异:

cmp -l ora.dmp monitor_10k_rows.dmp

     3 263 154
     4 201 131
     5 174 173
     6 103  75
    48  64  70
    58   0 340
    64   0   1
    65   0 104
    66   0 110
   541  60  61
   545  60  61
   552  60  61
   559  60  61
 20508   0  15
 20509   0 157
 20510   0 230
 20526   0  10
 20532   0  15
 20533   0 225
 20534   0 150
913437   0 226
913438   0  37
913454   0  10
913460   0   1
913461   0 104
913462   0 100

 ls -al  ora.dmp
-rw-r--r-- 1 oracle oinstall 999424 Jun 20 11:35 ora.dmp

 python -c 'print 999424-913462'
 85962

 od ora.dmp -j 913461 -N 1
3370065 000100
3370066

 od monitor_10k_rows.dmp -j 913461 -N 1
3370065 000000
3370066

即使我提取更多数据,差异仍然是 27 个字节,但地址/值不同:

cmp -l ora.dmp monitor_30k_rows.dmp

      3 245 134
      4 222 264
      5 377 376
      6  54  45
     48  36  43
     57   0   2
     58   0 216
     64   0   1
     65   0 104
     66   0 120
    541  60  61
    545  60  61
    552  60  61
    559  60  61
  20508   0  50
  20509   0 126
  20510   0 173
  20526   0  10
  20532   0  50
  20533   0 174
  20534   0 120
2674717   0 226
2674718   0  47
2674734   0  10
2674740   0   1
2674741   0 104
2674742   0 110

有些写法是一样的。有没有办法知道不同的字节地址?

 ls -al  ora.dmp
-rw-r--r-- 1 bicadmin bic 2760704 Jun 20 11:09 ora.dmp

python -c 'print 2760704-2674742'
85962

例如,在 DataDump 使用 Python 更新地址为 2674742 的原始副本后,如何更新我的监控副本?

COMPRESSION=DATA_ONLY如果我使用选项,也会发生完全相同的事情。

更新:想出了如何同步两个文件之间不同的字节:

def patch_file(fn, diff):
    for line in diff.split(os.linesep):
        if line:
            addr, to_octal, _ = line.strip().split()
            with open(fn , 'r+b') as f:
                f.seek(int(addr)-1)
                f.write(chr(int (to_octal,8)))

diff="""
     3 157 266
     4 232 276
     5 272 273
     6  16  25
    48  64  57
    58 340   0
    64   1   0
    65 104   0
    66 110   0
   541  61  60
   545  61  60
   552  61  60
   559  61  60
 20508  15   0
 20509 157   0
 20510 230   0
 20526  10   0
 20532  15   0
 20533 225   0
 20534 150   0
913437 226   0
913438  37   0
913454  10   0
913460   1   0
913461 104   0
913462 100   0
"""

patch_file(f3,diff)     
4

1 回答 1

0

用 Python写了一个补丁:

addr=[3 , 4 , 5 , 6 , 48 , 58 , 64 , 65 , 66 , 541 , 545 , 552 , 559 , 20508 , 20509 , 20510 , 20526 , 20532 , 20533 , 20534 ]
last_range=[85987, 85986, 85970, 85964, 85963, 85962]

def get_bytes(addr):
    out =[]
    with open(f1 , 'r+b') as f:
        for a in addr:
            f.seek(a-1)
            data= f.read(1)
            hex= binascii.hexlify(data)
            binary = int(hex, 16)
            octa= oct(binary)
            out.append((a,octa))

    return out


def patch_file(fn, bytes_to_update):
    with open(fn , 'r+b') as f:
        for (a,to_octal) in bytes_to_update:
            print (a,to_octal)
            f.seek(int(a)-1)
            f.write(chr(int (to_octal,8)))


if 1:
    from_file=f1
    fsize=os.stat(from_file).st_size
    bytes_to_read = addr + [fsize-x for x in last_range]

    bytes_to_update = get_bytes(bytes_to_read)  
    to_file =f3
    patch_file(to_file,bytes_to_update)

我进行dmp文件监控的原因是因为它将备份时间减少了一半。

于 2017-06-21T14:04:35.127 回答