Skip to content
Advertisement

Repack tar.gz to tar and exclude some files

I have a big backup.tar.gz file (260 GB) and about 160 GB of free storage space. Backup file contains three big dumb file (old backups, about 190 GB), which is not needed. So I want to untar backup.tar.gz to pipe excluding some files and tar it back without gzip. I have a text file, which contain names of dumb files. So I need something like: tar -xz --exclude-from='exclude.lst' -f backup.tar.gz -O - | tar cfv backup.tar -T -, but it seems not work.

After a first answer, I found a solution here https://unix.stackexchange.com/questions/80239/efficiently-remove-files-from-large-tgz

Advertisement

Answer

This question belongs on https://superuser.com/ or https://unix.stackexchange.com/.

tar x -O just concatenates the contents of all the files. This loses filenames and other metadata, including even where the boundaries between files were.

Use GNU tar --delete to rewrite a tar without some of the original members. Since you have the names of all the files you want to exclude, this should be simple. Maybe zcat | tar --delete to avoid having tar recompress the output.

If this answer doesn’t steer you in the right direction, I can add more detail tomorrow.

I think I remember seeing an archive swiss-army-knife command-line program that probably had options to do this sort of thing, but a quick search didn’t find it.

Advertisement