creating size-limited tar files

andrea crotti andrea.crotti.0 at gmail.com
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:
    tar_file.addfile(remaining_files.pop())
    if size(tar_file) >= limit:
         close(tar_file)
         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?
thanks


More information about the Python-list mailing list