I couldn't get the original site backup script at the top of this thread to run without errors, so I made some modifications:
<?
$datestamp = date("Y-m-d_H-i-s"); // Current date to append to filename of backup file in format of YYYY-MM-DD_HR-MN-SC (hours-mins-secs)
/* CONFIGURE THE FOLLOWING VARIABLES TO MATCH YOUR SETUP */
$filename= "yoursite_backup-$datestamp.tar"; // The name of the dump file
$ftp_server = "111.111.111.111"; // Name or IP. Shouldn't have any trailing slashes and shouldn't be prefixed with ftp://
$ftp_port = "21"; // FTP port - blank defaults to port 21
$ftp_username = "anonymous"; // FTP account username
$ftp_password = ""; // FTP account password - blank for anonymous
$lplogin = "YOURLOGIN"; // Set this to your LP Login name. It will be used in path statements
// If you don't want to back up your entire directory add additional subdirectories before the star (wildcard).
$command = "tar cvf ~/$filename /home/$lplogin/*";
$result = exec($command);
$command = "gzip -9 -S .gz ~/$filename";
$result = exec($command);
// The filename variable needed to get updated, because your actual backup file got renamed by gzip
// I just decided to create a new variable to hold the final file name.
$finalfile = $filename . ".gz";
// set up basic connection
$ftp_conn = ftp_connect($ftp_server);
// Turn PASV mode on or off
ftp_pasv($ftp_conn, false);
// login with username and password
$login_result = ftp_login($ftp_conn, $ftp_username, $ftp_password);
// check connection
if ((!$ftp_conn) || (!$login_result))
{
echo "FTP connection has failed.";
echo "Attempted to connect to $ftp_server for user $ftp_username";
exit;
}
else
{
echo "Connected to $ftp_server, for user $ftp_username";
}
// upload the file
// Some changes here from Scanman's original script. Removed the hard-coded "foo" file
// and using the final file name for the destination file.
// note that this uploads the file to $ftp_user's FTP home directory - a personal choice made by me
$upload = ftp_put($ftp_conn, $finalfile, "/home/$lplogin/$finalfile", FTP_BINARY);
// check upload status
if (!$upload)
{
echo "FTP upload has failed.";
}
else
{
echo "Uploaded $finalfile to $ftp_server.";
}
// close the FTP stream
ftp_close($ftp_conn);
unlink("/home/$lplogin/$finalfile"); //delete the backup file from the server
?>
Message or email me if you are having trouble with this script. It took me several hours of toying with Scanman's original to get it working for my configuration, so credit to him for the inspiration and framework.