关注this question,我试图以有效的方式将带有bz2压缩的json文件的40 GB TAR file加载到PostgreSQL中。
根据上面提到的答案,我试图分离流程并使用外部工具创建以下流程。
我到达bzcat时遇到错误,这是我必须构建执行上述操作的行:
pipeline = [filename[1:3] + " && ", # Change drive to H so that TAR can find the file without a drive name (doesn't like absolute paths, apparently).
'"C:\\Tools\\GnuWin32\\gnuwin32\\bin\\bsdtar" vxOf ' + filename_nodrive + ' "*.bz2"', # Call to tar, outputs to stdin
" | C:\\Tools\\GnuWin32\\gnuwin32\\bin\\bzcat.exe"#, # Forward its output to bzcat
' | python "D:\Cloud\Dropbox\Coding\GitHub\pyTwitter\pyTwitter_filehandling.py"', # Extract Tweets
' | "C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -1f copy.sql ' + secret_login_d
]
module_call = "".join(pipeline)
module_call = "H: && "C:\Tools\GnuWin32\gnuwin32\bin\bsdtar" vxOf "Twitter datastream/Sourcefiles/archiveteam-twitter-stream-2013-01.tar" "*.bz2" | C:\Tools\GnuWin32\gnuwin32\bin\bzcat.exe | python "D:\Cloud\Dropbox\Coding\GitHub\pyTwitter\pyTwitter_filehandling.py" | "C:\Program Files\PostgreSQL\9.4in\psql.exe" -1f copy.sql "user=xxx password=xxx host=localhost port=5432 dbname=xxxxxx""
执行TAR代码时,TAR文件输出到CMD提示符,暗示我一切都很好。但是,bzcat行会出错:
x 01/29/06/39.json.bz2
bzcat.exe: Data integrity error when decompressing.
Input file = (stdin), output file = (stdout)
It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.
运行-tvv告诉我:
huff+mtf data integrity (CRC) error in data
我尝试使用7-zip(GUI)提取相同的存档:这仍然有效。任何有关如何排除故障的帮助将不胜感激。我用GNUWin32运行Windows 8.1。
答案 0 :(得分:2)
bsdtar.exe是文件数据中的translating newline个字节,进入DOS CRLF序列,导致bzip2输出流损坏。
GNU tar在使用相对路径时起作用,但它不处理Windows中的绝对路径。
您最好的选择是使用7-zip:
7z.exe x -so -ir!*.json.bz2 archive.tar | bzcat | ...