I ran across this script, and would like to use it to backup my websites. It appears to be pretty close to ready, but the script was designed to backup a server with many sites and databases, and I only need to load it on one site. The script needs to backup the current site which will be /public_html, zip it, name it with a date timestamp, then upload it to a directory on an FTP server. (would be great if I could tell the script a directory to exclude also) The script will also need to upload the tar'd sql database as well to the FTP server. Once the backup is done it will need to delete the files from the current server so its not included in the next backup. Basically everything the script below is supposed to do, but needs tweaked so I can put it on my cpanel account I am looking to pay about $15 to have these minor tweaks made. I pay via paypal ASAP. Please let me know if you are interested. THanks <?php set_time_limit(0); /*********************************************************** | | Eric's super server backup script | ***********************************************************/ $nDays = 5; // How many days of backups to keep? /************************************** | MySQL variables ***************************************/ $bBackupMySQL = true; // Do you want to backup MySQL databases? $mysql = '/usr/bin/mysql'; $mysqldump = '/usr/bin/mysqldump'; $mysql_server = 'localhost'; $mysql_username = 'root'; $mysql_password = 'rootpw'; /************************************** | httpdocs variables ***************************************/ $bBackuphttpd = true; // Do you want to backup httpd (web) docs? $cVhostsDir = '/var/www/vhosts/'; // Include trailing slash /************************************** | Used to compress backup data ***************************************/ $tar = '/bin/tar'; /************************************** | Where you'll be running the script, most likely ***************************************/ $workingDir = '/home/username/backups/'; /************************************** | Amazon S3 set-up ***************************************/ $bAMZNS3 = true; // Backup to S3? if ($bAMZNS3) { $accessKeyId = ''; $secretAccessKey = ''; $bucketName = 'your-bucket'; /** * Amazon S3 PHP class * * @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class */ include('s3-php5-curl/S3.php'); } // ends if ($bAMZNS3) /************************************** | FTP set-up ***************************************/ $bFTP = false; // Backup to FTP? if ($bFTP) { $ftp_server = '127.0.0.1'; $ftp_username = 'ftpuser'; $ftp_password = 'ftppass!'; } // ends if ($bFTP) /************************************** | What suffix to add to filenames | if daily, make it the date | if you're going to run this hourly, or 2x / day, make it unique ***************************************/ $suffix = date("Ymd"); /*********************************************************** | | Done editing script | ***********************************************************/ chdir($workingDir); $oMysql = mysql_connect($mysql_server, $mysql_username, $mysql_password); if ($bAMZNS3) { $s3 = new S3($accessKeyId, $secretAccessKey); } // ends if ($bAMZNS3) if ($bFTP) { $oFTP = ftp_connect($ftp_server); ftp_login($oFTP, $ftp_username, $ftp_password); } // ends if ($bFTP) /////////////////////////////////////////////////////////// // Mysql Database Backups /////////////////////////////////////////////////////////// if ($bBackupMySQL) { // Get a list of the databases $oDBList = mysql_list_dbs($oMysql); while ($rsData = mysql_fetch_object($oDBList)) { $cDatabase = $rsData->Database; $cSQLFilename = $cDatabase . '_' . $suffix . '.sql'; $cTarGZFilename = $cSQLFilename . '.tar.gz'; // Dump them $cliResult = `$mysqldump -u$mysql_username -p$mysql_password $cDatabase > $cSQLFilename`; // Tar them up $cliResult = `$tar -cpzf $cTarGZFilename $cSQLFilename`; unlink($cSQLFilename); if ($bAMZNS3) { // Send to Amazon $s3->putObjectFile($cTarGZFilename, $bucketName, $cTarGZFilename, S3::ACL_PRIVATE); } // ends if ($bAMZNS3) if ($bFTP) { // FTP to server ftp_put($oFTP, $cTarGZFilename, $cTarGZFilename, FTP_BINARY); } // ends if ($bFTP) echo("Saved $cTarGZFilename\n"); // Cleanup unlink($cTarGZFilename); } // ends while ($rsData = mysql_fetch_object($oDBList)) } // ends if ($bBackupMySQL) /////////////////////////////////////////////////////////// // Ends MySQL Backups /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // Mysql httpdocs Backups /////////////////////////////////////////////////////////// if ($bBackuphttpd) { // Get a list of the sites chdir($cVhostsDir); if ($oDir = opendir($cVhostsDir)) { while (false !== ($cFilename = readdir($oDir))) { if (!in_array($cFilename, array('.', '..', 'chroot', 'default', '.skel'))) { $cTarGZFilename = $cFilename . '_' . $suffix . '.tar.gz'; $cTarGZPath = $workingDir . $cTarGZFilename; $cSourceFiles = $cFilename . '/httpdocs/'; // Tar them up `$tar -cpzf $cTarGZPath $cSourceFiles`; if ($bAMZNS3) { // Send to Amazon $s3->putObjectFile($cTarGZPath, $bucketName, $cTarGZFilename, S3::ACL_PRIVATE); } // ends if ($bAMZNS3) if ($bFTP) { // FTP to server ftp_put($oFTP, $cTarGZFilename, $cTarGZPath, FTP_BINARY); } // ends if ($bFTP) echo("Saved $cTarGZFilename\n"); // Cleanup unlink($cTarGZPath); } // ends if (!in_array($cFilename, array(... } // ends while (false !== ($cFilename = readdir($oDir))) closedir($oDir); } // ends if ($oDir = opendir('/var/www/vhosts/')) chdir($workingDir); } // ends if ($bBackuphttpd) /////////////////////////////////////////////////////////// // Ends httpdocs backups /////////////////////////////////////////////////////////// echo("Done writing backup - starting cleanup.\n"); /////////////////////////////////////////////////////////// // Cleanup old files from the server /////////////////////////////////////////////////////////// if ($bAMZNS3) { $aS3Files = $s3->getBucket($bucketName); while (list($cFilename, $rsFileData) = each($aS3Files)) { if ($rsFileData['time']+($nDays*24*60*60) < time(void)) { $s3->deleteObject($bucketName, $cFilename); } // ends if ($tsModTime+432000 < time(void)) } // ends while (list($cFilename, $rsFileData) = each($s3->getBucket($bucketName))) } // ends if ($bAMZNS3) if ($bFTP) { $list=@ftp_rawlist($oFTP, '.') ; $items=array() ; foreach($list as $_) preg_replace( '`^(.{10}+)(\s*)(\d{1})(\s*)(\d*|\w*)'. '(\s*)(\d*|\w*)(\s*)(\d*)\s'. '([a-zA-Z]{3}+)(\s*)([0-9]{1,2}+)'. '(\s*)([0-9]{2}+):([0-9]{2}+)(\s*)(.*)$`Ue', '$items[]=array( "rights"=>"$1", "number"=>"$3", "owner"=>"$5", "group"=>"$7", "file_size"=>"$9", "mod_time"=>"$10 $12 $14:$15", "file"=>"$17", "type"=>print_r((preg_match("/^d/","$1"))?"dir":"file",1));', $_) ; # :p // Remove anything older than 5 days foreach ($items as $rsFTPFile) { $cFilename = trim($rsFTPFile['file']); $tsModTime = strtotime($rsFTPFile['mod_time']); if ($tsModTime+($nDays*24*60*60) < time(void)) { ftp_delete($oFTP, $cFilename); } // ends if ($tsModTime+432000 < time(void)) } // ends foreach ($items as $rsFTPFile) ftp_close($oFTP); } // ends if ($bFTP) /////////////////////////////////////////////////////////// // Ends cleanup /////////////////////////////////////////////////////////// ?> PHP: