简体   繁体   English

合并分割的tar.gz文件Linux命令的某些部分

[英]Merge some parts of a split tar.gz file Linux command

I have a large tar.gz file (approximately 63 GB) on a linux server. 我在Linux服务器上有一个大的tar.gz文件(大约63 GB)。 This file has about 1000 compressed csv files. 该文件包含大约1000个压缩的csv文件。 I need to save the data of csv files in a database. 我需要将csv文件的数据保存在数据库中。

I can't extract whole file in one go due to limited space on the server. 由于服务器空间有限,我无法一次性提取整个文件。 So I split the tar.gz file into 5 parts (4 parts of 15 GB and 1 of 3GB) but did not merge all of them as the server won't have any space left when extraction would be done. 因此,我将tar.gz文件分为5个部分(15 GB的4个部分和3GB的1个部分),但是没有合并所有文件,因为提取完成后服务器将没有任何空间。 I merged the first two parts to make a new tar.gz file and extracted the csv files from that. 我合并了前两部分,以创建一个新的tar.gz文件,并从中提取了csv文件。

When I tried to merge the last 3 parts, it did not make a valid tar.gz file and that file could not be extracted. 当我尝试合并最后3个部分时,它没有生成有效的tar.gz文件,因此无法提取该文件。 This problem was not because of server space because I deleted the files that were no longer required after extraction from first two parts. 此问题不是由于服务器空间不足,因为从前两部分提取后,我删除了不再需要的文件。

Is there any way through which the last 3 parts of the split tar.gz file can be merged in a valid tar.gz format and then extracted? 有什么方法可以将分割后的tar.gz文件的最后3个部分合并为有效的tar.gz格式,然后将其提取?

Command used to split : 用于拆分的命令:

split -b 15G file.tar.gz parts

Command used to merge : 用于合并的命令:

cat parts* > combined.tar.gz

Command used to extract : 用于提取的命令:

tar zxvf file.tar.gz -C folderwhereextracted

You can use short shell script: 您可以使用短壳脚本:

#/bin/sh

path='./path'
list="$path/*.tar.gz"
for file in `ls ./da/*.tar.gz.*`
    do
        let i++

        if [[ -f $(find $path/*.tar.gz.$i) ]]
            then
                echo "file $path/*.tar.gz.$i found."
                list="$list $path/*.tar.gz.$i"
            else
                echo "file $path/*.tar.gz.$i not found!"
        fi
    done
cat $list > full.tar.gz
tar zxvf ./full.tar.gz -C $path
# rm -rf $list

Put your path to variable with the same name. 将您的路径放入具有相同名称的变量。 Uncomment last line to remove source files after untar. 取消注释最后一行以在解压缩后删除源文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM