bash 并行 tar 与大文件夹的拆分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18557195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:25:29  来源:igfitidea点击:

Parallel tar with split for large folders

bashparallel-processingsplitgnutar

提问by Arman

I am have really huge folder I would like to gzip and split them for archive:

我有一个非常大的文件夹,我想 gzip 并将它们拆分为存档:

#!/bin/bash
dir=
name=
size=32000m
tar -czf /dev/stdout ${dir} | split -a 5  -d -b $size - ${name}

Are there way to speed up this with gnu parallel? thanks.

有没有办法用 gnu 并行加速这个?谢谢。

回答by konsolebox

It seems the best tool for parallel gzip compression is pigz. See the comparisons.

似乎并行 gzip 压缩的最佳工具是pigz。请参阅比较

With it you can have a command like this:

有了它,你可以有一个这样的命令:

tar -c "${dir}" | pigz -c | split -a 5 -d -b "${size}" - "${name}"

With its option -pyou could also specify the number of threads to use (default is the number of online processors, or 8 if unknown). See pigz --helpor man pigzfor more info.

使用它的选项,-p您还可以指定要使用的线程数(默认为在线处理器数,如果未知则为 8)。查看pigz --helpman pigz了解更多信息。

UPDATE

更新

Using GNU parallel you could do something this:

使用 GNU 并行,您可以执行以下操作:

contents=("$dir"/*)
outdir=/somewhere
parallel tar -cvpzf "${outdir}/{}.tar.gz" "$dir/{}" ::: "${contents[@]##*/}"