creating size-limited tar files

andrea crotti andrea.crotti.0 at
Wed Nov 7 18:13:47 CET 2012

Simple problem, given a lot of data in many files/directories, I
should create a tar file splitted in chunks <= a given size.

The simplest way would be to compress the whole thing and then split.

At the moment the actual script which I'm replacing is doing a
"system('split..')", which is not that great, so I would like to do it
while compressing.

So I thought about (in pseudocode)

while remaining_files:
    if size(tar_file) >= limit:
         tar_file = new_tar_file()

which might work maybe, but how do I get the current size?  There
should be tarinfo.size but it doesn't exist on a TarFile opened in
write mode, so should I do a stat after each flush?

Any other better ideas otherwise?

More information about the Python-list mailing list