d33*_*tah 9 tar large-files compression disk-usage
我有大约 200 万 (60GiB) 个 gzip 小文件,我想创建一个压缩存档,其中包含所有这些文件的未压缩版本。不幸的是,我不能只是解压缩它们然后创建压缩档案,因为我只有大约 70GiB 的可用磁盘空间。换句话说,tar --file-filter="zcat" zcf file.tar.gz directory
如果--file-filter
GNU tar 中不存在命令行开关,我该如何做?
一个选项可能是使用avfs
(这里假设一个 GNU 系统):
mkdir ~/AVFS &&
avfsd ~/AVFS &&
cd ~/AVFS/where/your/gz/files/are/ &&
find . -name '*.gz' -type f -printf '%p#\0' |
tar --null -T - --transform='s/.gz#$//' -cf - | pigz > /dest/file.tar.gz
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所尝试的 - 它似乎有效,但即使使用 PyPy 也非常慢:
#!/usr/bin/python
import tarfile
import os
import gzip
import sys
import cStringIO
tar = tarfile.open("/dev/stdout", "w|")
for name in sys.stdin:
name = name[:-1] # remove the trailing newline
try:
f = gzip.open(name)
b = f.read()
f.close()
except IOError:
f = open(name)
b = f.read()
f.close()
# the [2:] there is to remove ./ from "find" output
ti = tarfile.TarInfo(name[2:])
ti.size = len(b)
io = cStringIO.StringIO(b)
tar.addfile(ti, io)
tar.close()
Run Code Online (Sandbox Code Playgroud)
用法:find . | script.py | gzip > file.tar.gz
归档时间: |
|
查看次数: |
1768 次 |
最近记录: |