Is any way to split zip archive to sections?
Tim Williams
tim at tdw.net
Sat Mar 31 11:32:19 EDT 2007
On 30/03/07, Durumdara <durumdara at gmail.com> wrote:
> Hi!
>
> I want to create some backup archives with python (I want to write a backup
> application in Python).
> Some package managers (7z, arj, winzip) can create splitted archives (1
> mega, 650, 700 mega, etc).
>
> Because I want to ftp these results to a ftp server, I want to split large
> volumes to 15 mb sections.
>
> Can I do it with any python wrapper automatically (like in Cobian), or I
> need to create the large volume, and next split it with another tool?
>
> Or anybody knows about a command line tool (like 7z, or arj) that can expand
> the splitted archive (and I can add files with them from Python one by one)?
>
If you are iterating through a list of files to be backed up, and
adding them to a ZIP one-by-one then you could use something like this
which adds each file until the zip is over 15mb - then it closes the
ZIP and creates the next one.
Not tested or optimised :)
---------------------------------------------------------------------------------------------------
import zipfile
archive_num = 1
outfile = zipfile.ZipFile('/zips/archive%s.zip' % archive_num, "w")
zsize = 0
for full_name in filelist:
full_name_path = os.path.join(full_name, full_path)
if zsize > 15728640 : # 15mb
outfile.close()
archive_num += 1
outfile = zipfile.ZipFile('/zips/archive%s.zip' % archive_num, "w")
zsize= 0
outfile.write( full_name_path , full_name_path ,
zipfile.ZIP_DEFLATED) # add the file
zsize += outfile.getinfo(full_name_path).compress_size # get
compressed size of file
outfile.close()
More information about the Python-list
mailing list