PDA

View Full Version : How do I backup my sites?


Atjeu
03-23-2002, 09:49 PM
Here is a nice script to backup your server and ftp the files to your ftp server at home. Just replace /home in the $directorytobackup variable with whichever directory you want to back up and then replace host with your ftp host, and replace username with your username and password with your password. Then chmod this file to 755 and execute it - you can even set it up on a cron so it will do it on a daily or weekly basis. Make sure you have the perl module Net:FTP installed - if you dont have it, you can get it from cpan.

#!/usr/bin/perl
use Net::FTP;
$directorytobackup='putthefullpathtowhatyouwanttob ackuphere';

################################################## ################
#Backup the $directorytobackup

#tar and gzip the file or directory
`tar -cz /$directorytobackup >> $directorytobackup.tgz`;

#ftp the compressed file to the remote ftp server

$ftp = Net::FTP->new("host", Debug => 0);
$ftp->login("username",'password');
$ftp->cwd("");
$ftp->put("$directorytobackup.tgz");
$ftp->quit;

#remove the local copy of the compressed file
`rm -rf $directorytobackup.tgz`;
print "Done with $directorytobackup\n";