PHP:
backup.pl
================
#!/usr/bin/perl
#### CONFIG ####
$backupHour = 3; # TIME TO RUN THE backup
$backupPath = "/backup"; #This is the folder where your backup file set file is stored
$backupFileName = "backup.tar.gz"; #The name you want to give to your tar file
$backupFileList = "file_list.txt"; #The list that you use to determine what parts to back up
$HostHasMySQL = 0; # 1 = YES, 0 = NO
$MySQLRootPassword = '';
$MySQLbackupFileList = "mysql_list.txt"; #The list that you use to determine which databases to backup.
################
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($hour == $backupHour) {
if ($HostHasMySQL == 1) {
&DumpDatabases;
}
&backupFiles;
}
#### SUBS ####
sub backupFiles
{
# remove old backup file
$systemresult = system("rm $backupPath\/$backupFileName");
# create .tar.gz file
$systemresult = system("tar czvf $backupPath\/$backupFileName -T $backupPath\/$backupFileList \&>\/dev\/null");
}
sub DumpDatabases
{
my $name;
if (open(DBLIST, "$backupPath\/$MySQLbackupFileList")) {
while (<DBLIST>) {
if (/^\s*\#/ ¦¦ /^\s*$/) {
# Ignore Comments and Blank Lines
} elsif ( /^\s*([\w]+)\s*/ ) {
$name = $1;
$systemresult = system("mysqldump --opt --user=root --password=$MySQLRootPassword $name > $backupPath$
}
}
close (DBLIST);
}
}
Create a file, file_list.txt, and insert folders that you want backing up, into a new line.
eg:
/www/home
/www/public
/etc/passwd
The bottom one, shows that you can also back individual files up. If you put a folder in the list, it will backup the contents of that folder, and all subfolders.
For the mysql_list.txt - just enter the dabase names onto separate lines.
eg:
site1dbase
site2dbase
mydbase
Set it up to run either on cron, or run it from the cammand line.
A tar.gz file will be created - if you want to get this off, then you will need to download it off your server - but beware, if all your sites and databases are in it, it could be a large file!
Hope this helps,