How to split a tar file into smaller parts at file boundaries

tar

I have a tar file that I want to split into multiple smaller tar files. This would be easy with split, but I want the splitted files to be fully usable tar files themselves, which split can't do as it will split at arbitrary points, not at file boundaries.

So how to split a tar file into smaller parts at file boundaries, so that no file ends up being half in one tar and half in the other tar?

Solutions that don't use tar and accomplish the task by other means would be welcome as well.

PS: Yes, there will be cases where this isn't possible (tar with files larger then the split size).

Best Answer

There is a tool, tarsplitter which safely splits tar archives. You specify the number of parts you want to split the archive into, and it will figure out where the file boundaries are.

https://github.com/AQUAOSOTech/tarsplitter

The output smaller archives won't be exactly the same size, but pretty close - assuming the files in the original archive don't have a lot of variation.

Example - split the archive "files.tar" into 4 smaller archives:

tarsplitter -p 4 -i files.tar -o /tmp/parts

Creating:

/tmp/parts0.tar
/tmp/parts1.tar
/tmp/parts2.tar
/tmp/parts3.tar