CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Backup (.tar.gz) of a site through perl

 



voshka
stranger

Oct 18, 2001, 2:05 PM

Post #1 of 5 (975 views)
Backup (.tar.gz) of a site through perl Can't Post

Can some one plese help me out?

I have subscribed to an ISP that promised me the ultimate web hosting package, including Telnet...

Or so I though! After I paid them for one year in advance, I have discovered that the telnet access is to... wait for it... the [profanity omitted] mail server!!!

My problem is that I am used to do much site maintenance through telnet, including regular backups. It takes for ages to FTP thousands and thousands of small files...

Is it at all possible to execute tar and gzip commands from a perl script?

Perhaps some one has already created such script, which can compress the contents of an entire directory?

Any help is greatly appreciated.

P.S. I am sure that my ISP would not look kindly to any full blown administration script such as webmin, so something very low key would be the perfect solution.



MouldyGoat
stranger

Oct 18, 2001, 2:59 PM

Post #2 of 5 (972 views)
Re: Backup (.tar.gz) of a site through perl [In reply to] Can't Post

Yep, it's possible - in fact there's a module to do just that - try looking under CPAN, it's under something like Archive::



voshka
stranger

Oct 18, 2001, 7:03 PM

Post #3 of 5 (970 views)
Re: Backup (.tar.gz) of a site through perl [In reply to] Can't Post

I cannot even install new software. I tried to install Perlmagic (for image magic) and got an angry email from the ISP.



MouldyGoat
stranger

Oct 19, 2001, 2:41 AM

Post #4 of 5 (968 views)
Re: Backup (.tar.gz) of a site through perl [In reply to] Can't Post

Well that really is quite poor. I just hope you didn't actually pay for this, if you abandon them you might want to try 34sp.com - that's what I use, they offer good support and they only charge 1 a month - you can get SSH access if you make a good case for it...



rGeoffrey
User / Moderator

Oct 27, 2001, 12:54 PM

Post #5 of 5 (960 views)
Re: Backup (.tar.gz) of a site through perl [In reply to] Can't Post

When you don't have telnet you can fake it through the web browser, but it does expose you to some potential security problems. One such system looks like...

Write a script that will present a form where the user can give
- username
- password
- a text area to type in what you would like to run in a shell script

Have that script call itself with those three bits of information and do a system call on the script capturing the STDERR and STDOUT in two files.

The script then redraws the form with the original input and two new text areas to show the files containing STDERR and STDOUT.

And lastly you remove the three temporary files to cover your tracks.

Then you are ready to go again.

This method is also useful for those times where scripts running in the browser run as a different user than you are and you need to get in and do some things like delete a file and need to do it as that other user. But remember this is a dangerous thing to do.


If you want to do this you might want to use this function...


Code
sub interact 
{
my ($script) = @_;
my ($file, $results, $errors);

$file = &Uniq_t_x ();
open (DATA, ">$file") or die "While printing file $file";
print DATA ("#!/bin/sh\n", $script);
close DATA;

chmod (0744, $file);
system ("/bin/sh $file > $file.txt 2> $file.errs");

if (open (DATA, "$file.txt")) {
$results = join ('', <DATA>);
close DATA;
}

if (open (DATA, "$file.errs")) {
$errors = join ('', <DATA>);
close DATA;
}

unlink ($file);
unlink ("$file.txt");
unlink ("$file.errs");
return ($results, $errors);
} #interact

The three filenames (script, script.errs, and script.txt) use a "unique" filename that you can generate any way you want but I use this...


Code
sub Uniq_t_x 
{
my($job, $now, $uniq);

$job = `echo \$\$`;
$now = time();
$job = $job % 65536;
$uniq = sprintf("% 08X% 04X", $now, $job) ;

return ($uniq);

} # Uniq_t_x

This can be a very useful little script and it can be yours if you fill in a few missing pieces.

PS. Did I mention that this is leaves you open to real security problems?

Edited to add a space in the sprintf statement between the '%' and the '0' so it looks right on the screen. You will need to remove them to use the function.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives