如何解压缩mongo日志文件

2024-06-19 19:36:28 发布

您现在位置:Python中文网/ 问答频道 /正文

正如我所探讨的,Mongodb创建的日志文件是使用snapy压缩算法压缩的。但我无法解压缩这个压缩的日志文件。它会在试图解压缩时出错

Error stream missing snappy identifier

我用来解压的python代码如下:

import collections
import bson
from bson.codec_options import CodecOptions
import snappy
from cStringIO import StringIO
try:
    with open('journal/WiredTigerLog.0000000011') as f:
        content = f.readlines()
        fh = StringIO()
        snappy.stream_decompress(StringIO("".join(content)),fh)
        print fh
except Exception,e:
    print str(e)
    pass

请帮帮我,我走不了路了


Tags: 文件fromimportstreammongodberrorcontent压缩算法
1条回答
网友
1楼 · 发布于 2024-06-19 19:36:28

There's two forms of Snappy compression, the basic form and the streaming form. The basic form has the limitation that it all must fit in memory, so the streaming form exists to be able to compress larger amounts of data. The streaming format has a header and then subranges that are compressed. If the header is missing, it sounds like maybe you compressed using the basic form and are trying to uncompress with the streaming form. https://github.com/andrix/python-snappy/issues/40

如果是这样,请使用decompress而不是stream_decompress。在

但如果数据根本没有被压缩:

with open('journal/WiredTigerLog.0000000011') as f:
    for line in f:
        print line

可以工作。在

Minimum log record size for WiredTiger is 128 bytes. If a log record is 128 bytes or smaller, WiredTiger does not compress that record. https://docs.mongodb.com/manual/core/journaling/

相关问题 更多 >