Following is a CGI program I use to do just what you're describing. The file being uploaded is a zip file, whose members may or may not exist in the backup archive. Those members which exist, but with a different CRC, are updated; those which don't, simply added. I've left out some authorization code, which you should come up with to fit your situation. (You don't want malicious users backing up their files on your system!) I hope it helps. (Sorry 'bout the indents. SOPW seems to be a tab mangler.)
#!/usr/bin/perl -w use strict; use Archive::Zip; use CGI; use CGI::Carp qw(fatalsToBrowser); use Digest::MD5 qw(md5_base64); my $BackupPath = '/myserver/mybackupdir'; my $InpFile = $query->param('Backup'); undef $/; my $InpData = <$InpFile>; my $len = length($InpData); print "Content-type: text/plain\n\n"; my $NewFile; if ($len) { $NewFile = rename("$BackupPath/remote.zip", "$BackupPath/remote.ba +k") ? 'send.zip' : 'remote.zip'; open BAK, ">$BackupPath/$NewFile" or die "Can't open send.zip to wri +te: $!"; print BAK $InpData; close BAK; print "Received: $InpFile. Saved as: $NewFile. Length: $len bytes\n" +; } exit if $NewFile eq 'remote.zip'; my $local = Archive::Zip->new("$BackupPath/send.zip") or die "Can't ac +cess send.zip"; my @local_files = $local->members(); my $remote = Archive::Zip->new("$BackupPath/remote.bak") or die "Can't + access remote.bak"; my @remote_files = $remote->members(); my %remote_index; foreach (@remote_files) { $remote_index{$_->fileName()} = $_->crc32String() } foreach (@local_files) { my $name = $_->fileName(); print "$name: "; if (exists $remote_index{$name}) { if ($remote_index{$name} eq $_->crc32String()) { print "Exists unchanged.\n"; next } else { print "Needs updating.\n"; $remote->replaceMember($name, $_) } } else { print "Doesn't yet exist.\n"; $remote->addMember($_) } } $remote->writeToFileNamed("$BackupPath/remote.zip") && die "Error writ +ing remote.zip."; unlink "$BackupPath/remote.bak"; #Or not. I had to to keep from going +over my host's storage limit. print "*** Zip file updated. ***\n";

In reply to Re: Combining or Merging 2 zip files. by Dr. Mu
in thread Combining or Merging 2 zip files. by eric256

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.