Munkholm
02-15-2011, 06:24 AM
Hi everyone.
I?m using the mod vBulletin Cron Based Database Backup (https://vborg.vbsupport.ru/showthread.php?t=231481) to create compressed backups at the server. This is working great, but for redundancy I want to keep a "off site" backup of everything.
Though I have no experience with PHP what so ever, I?ve been able to put the below script together, it creates a compressed file of the entire file system, including the DB backup made by the above mentioned mod, and successfully transfers the compressed backup file to my FTP server.
But... The srcipt is returning a server 500 error on me, however it?s working just fine. Anyone knows what the error is ?
I?d suppose that this could be used by others too, if it gets cleaned up by someone who knows PHP ;)
BTW: The script is set to run as a Scheduled Task from the AdminCP.
<?php
$ftp_server="aaaa.bbbbb.com";
$ftp_username="myuser";
$ftp_password="mypass";
$ftp_filename="fullbackup.tar.gz"; // do not edit
$ftp_dir="/www/myftpsite.com/backups";
// Do NOT edit below
// create compressed file to transfer
exec('tar -czf fullbackup.tar.gz /web/myforum/public_html/');
// make the ftp connction
$ftp_fd = ftp_connect($ftp_server);
// log in to ftp
$ftp_login = ftp_login($ftp_fd, $ftp_username, $ftp_password );
// check connection
if ((!$ftp_fd) || (!$ftp_login))
die("FTP connection has failed!");
echo "* ftpconnect: success"."\n";
ftp_pasv($ftp_fd, true);
echo "* pwd : ".ftp_pwd( $ftp_fd )."\n";
echo "* ls : " .print_r( ftp_nlist($ftp_fd, "."),true )."\n";
// change the directory
if (ftp_chdir($ftp_fd, $ftp_dir)) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
echo "Couldn't change directory\n";
}
// upload the file
$ftp_upload = ftp_put($ftp_fd, $ftp_filename, $ftp_filename, FTP_BINARY);
ftp_close($ftp_fd);
// check upload status
if (!$ftp_upload)
die("FTP upload has failed!");
echo "* ftpupload: success"."\n";
//delete the temp compressed file
unlink($ftp_filename);
?>
I?m using the mod vBulletin Cron Based Database Backup (https://vborg.vbsupport.ru/showthread.php?t=231481) to create compressed backups at the server. This is working great, but for redundancy I want to keep a "off site" backup of everything.
Though I have no experience with PHP what so ever, I?ve been able to put the below script together, it creates a compressed file of the entire file system, including the DB backup made by the above mentioned mod, and successfully transfers the compressed backup file to my FTP server.
But... The srcipt is returning a server 500 error on me, however it?s working just fine. Anyone knows what the error is ?
I?d suppose that this could be used by others too, if it gets cleaned up by someone who knows PHP ;)
BTW: The script is set to run as a Scheduled Task from the AdminCP.
<?php
$ftp_server="aaaa.bbbbb.com";
$ftp_username="myuser";
$ftp_password="mypass";
$ftp_filename="fullbackup.tar.gz"; // do not edit
$ftp_dir="/www/myftpsite.com/backups";
// Do NOT edit below
// create compressed file to transfer
exec('tar -czf fullbackup.tar.gz /web/myforum/public_html/');
// make the ftp connction
$ftp_fd = ftp_connect($ftp_server);
// log in to ftp
$ftp_login = ftp_login($ftp_fd, $ftp_username, $ftp_password );
// check connection
if ((!$ftp_fd) || (!$ftp_login))
die("FTP connection has failed!");
echo "* ftpconnect: success"."\n";
ftp_pasv($ftp_fd, true);
echo "* pwd : ".ftp_pwd( $ftp_fd )."\n";
echo "* ls : " .print_r( ftp_nlist($ftp_fd, "."),true )."\n";
// change the directory
if (ftp_chdir($ftp_fd, $ftp_dir)) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
echo "Couldn't change directory\n";
}
// upload the file
$ftp_upload = ftp_put($ftp_fd, $ftp_filename, $ftp_filename, FTP_BINARY);
ftp_close($ftp_fd);
// check upload status
if (!$ftp_upload)
die("FTP upload has failed!");
echo "* ftpupload: success"."\n";
//delete the temp compressed file
unlink($ftp_filename);
?>