Re: Is any way to split zip archive to sections?



On 30/03/07, Durumdara <durumdara@xxxxxxxxx> 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()
.



Relevant Pages

  • Re: Simple script to make .png thumbnails from .zip archive...
    ... I'm able to read a .jpg from a .zip archive, ... but it is of "type" ZipFile. ... I don't know zipfile by heart, but python official documentation is ... The reason for this is I want to have tuhmbnails for these archives in ...
    (comp.lang.python)
  • Re: Is any way to split zip archive to sections?
    ... I want to create some backup archives with python (I want to write a ... application in Python). ... Some package managers (7z, arj, winzip) can create splitted archives (1 ...
    (comp.lang.python)
  • Re: Is any way to split zip archive to sections?
    ... I want to create some backup archives with python (I want to write a ... application in Python). ... Some package managers (7z, arj, winzip) can create splitted archives (1 ...
    (comp.lang.python)
  • Re: would be nice: import from archive
    ... Right after posting the message I found the 'Index of Python ... and there is PEP 273, 'Import Modules from Zip Archives', submitted by ... It would be nice to be able to save configurations (combinations ... > (yes, I'm Mr. Perl, but I'm using Python, after all Perl is not my middle ...
    (comp.lang.python)