Category: CGI programming
Author/Contact Info
Description: I created this script to play around with Archive::Zip.

Tested on win32, but could work on X systems too.

The script creates and sends a Zip archive to the client. It will add a full dir tree and you can suggest a downloadname for the zipfile.

Might be handy to backup/mirror sites that have slow FTP but good HTTP.

It uses a simple config file with two entries:
file: 'getbackup.conf'

use Archive::Zip;
use Archive::Zip::Tree;
my $zip = Archive::Zip->new();
our $programdir = ".";
$programdir = $1 if $0=~/^(.+[\\\/])[^\\\/]+$/;

my $docroot = "";

open(CONFIG,"$programdir/getbackup.conf") || &DieConfig;
    $docroot =$1 if /root\=(.+)[\n\r\s]*/i;
    $backupname =$1 if /name\=(.+)[\n\r\s]*/i;

print STDOUT "HTTP/1.0 200 OK\n";
print STDOUT "Content-Type: application/x-downloads\n";
print STDOUT "Content-Disposition: attachment; filename=backup$backupn
print STDOUT "\n";

# add all readable files and directories below . as xyz/*
$zip->addTree( $docroot, './'); 

# and write them into a file
sub DieConfig {
    print STDOUT "Content-type: text/html\n\n";
    print STDOUT "Need getbackup.conf with docroot= and name= setting\
Replies are listed 'Best First'.
•Re: CGI - Zip tree archiver backup thing
by merlyn (Sage) on Feb 27, 2003 at 13:15 UTC
Re: CGI - Zip tree archiver backup thing
by PodMaster (Abbot) on Feb 28, 2003 at 06:58 UTC
    I've seen you use $0=~/^(.+[\\\/])[^\\\/]+$/; a couple of times now. Please use File::Basename, or File::Spec because they are portable solutions. BTW, I prefer __FILE__ ;)

    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.