Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

CGI - Zip tree archiver backup thing

by Vennis (Pilgrim)
on Feb 27, 2003 at 07:59 UTC ( #239024=sourcecode: print w/replies, xml ) Need Help??
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'
root=c:/temp
name=Tempdir

binmode(STDOUT);
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;
while(<CONFIG>){
    $docroot =$1 if /root\=(.+)[\n\r\s]*/i;
    $backupname =$1 if /name\=(.+)[\n\r\s]*/i;
 }
close(CONFIG);

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

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

# and write them into a file
$zip->writeToFileHandle(STDOUT,0);
sub DieConfig {
    print STDOUT "Content-type: text/html\n\n";
    print STDOUT "Need getbackup.conf with docroot= and name= setting\
+n";
    exit;
}
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://239024]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2021-01-20 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?