FarmerTodd Posted December 16, 2006 Posted December 16, 2006 I found a backup utility from TCH written by Bruce Richards / Andy Beckett and am getting an error when I run it: Warning: filetype() [function.filetype]: Lstat failed for (null) (errno=2 - No such file or directory) in /home/username/public_html/backups/backup.php on line 56 Warning: fopen(/home/username/backups/121606-0936am-bolderstaffing.zip) [function.fopen]: failed to open stream: No such file or directory in /home/username/public_html/backups/backup.php on line 62 Warning: filesize() [function.filesize]: Stat failed for /home/username/backups/121606-0936am-bolderstaffing.zip (errno=2 - No such file or directory) in /home/username/public_html/backups/backup.php on line 63 Warning: fread(): supplied argument is not a valid stream resource in /home/bolder/public_html/backups/backup.php on line 63 Warning: fclose(): supplied argument is not a valid stream resource in /home/bolder/public_html/backups/backup.php on line 64 Backup created and sent! File name /home/username/backups/121606-0936am-bolderstaffing.zip I edited my username out of the message FYI. I setup the variables as follows: // setup variables $remove_file = "yes"; // remove file when done -- recommended! $path= '/home/username/public_html/'; // Full path to backup $zipfile = "bolderstaffing.zip"; // backup file name $zippath = "/home/username/backups"; // path to save backup file $send_email = "yes"; // Do you want this backup sent to your email? Fill out the next 2 lines $to = "myemailaddress@domain.com"; // Who to send the emails to $from = "backup@domain.com"; // Who should the emails be sent from? $senddate = date("j F Y"); $subject = "Backup - $senddate"; // Subject in the email to be sent. $message = "Your backup is attached to this email"; // Brief Message. $use_ftp = "no"; // Do you want this backup uploaded to an ftp server? Fill out the next 4 lines $ftp_server = "localhost"; // FTP hostname $ftp_user_name = ""; // FTP username $ftp_user_pass = ""; // FTP password $ftp_path = "/"; // This is the path to upload on your ftp server! If you want to see the entire source for this code: <?php // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright © 2006 Bruce Richards / Andy Beckett | // | | // | Purpose: To backup a folder structure to a zip file and then FTP | // | the file to a remote server | // | | // | Requires: zip be installed on the server and that you are able | // | to use the passthru command of PHP, the TCH servers | // | do have zip installed and passthru can be used. | // | | // | WARNING: Depending on what you are backing up the files can be quite | // | large. Be sure you have enough space for what you are | // | backing up. Also, sending huge files via email is not | // | recommended. | // | | // +----------------------------------------------------------------------+ // | Author: Bruce Richards / Andy Beckett | // +----------------------------------------------------------------------+ // // setup variables $remove_file = "yes"; // remove file when done -- recommended! $path= '/home/xxxxx/public_html/'; // Full path to backup $zipfile = "bolderstaffing.zip"; // backup file name $zippath = "/home/xxxxx/backups"; // path to save backup file $send_email = "yes"; // Do you want this backup sent to your email? Fill out the next 2 lines $to = "farm_r_todd@xxxxx.com"; // Who to send the emails to $from = "backup@xxxxx.com"; // Who should the emails be sent from? $senddate = date("j F Y"); $subject = "Backup - $senddate"; // Subject in the email to be sent. $message = "Your backup is attached to this email"; // Brief Message. $use_ftp = "no"; // Do you want this backup uploaded to an ftp server? Fill out the next 4 lines $ftp_server = "localhost"; // FTP hostname $ftp_user_name = ""; // FTP username $ftp_user_pass = ""; // FTP password $ftp_path = "/"; // This is the path to upload on your ftp server! // Do not Modify below this line! $date = date("mdy-hia"); $zipname = "$zippath/$date-$zipfile"; passthru("nice -n 16 zip -q -r $zipname $path "); $filename2 = "$zipname"; if($send_email == "yes" ){ $fileatt_type = filetype($filename2); $fileatt_name = "".$date."-".$zipfile.""; $headers = "From: $from"; // Read the file to be attached ('rb' = read binary) $file = fopen($filename2,'rb'); $data = fread($file,filesize($filename2)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" ."Content-Type: multipart/mixed;\n" ." boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" ."--{$mime_boundary}\n" ."Content-Type: text/plain; charset=\"iso-8859-1\"\n" ."Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); // Add file attachment to the message $message .= "--{$mime_boundary}\n" ."Content-Type: {$fileatt_type};\n" ." name=\"{$fileatt_name}\"\n" ."Content-Disposition: attachment;\n" ." filename=\"{$fileatt_name}\"\n" ."Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" ."--{$mime_boundary}--\n"; // Send the message $ok = @mail($to, $subject, $message, $headers. "-f" .$from); if ($ok) { echo "<h4><center>Backup created and sent! File name $filename2</center></h4>"; } else { echo "<h4><center>Mail could not be sent. Sorry!</center></h4>"; } } if($use_ftp == "yes"){ $conn = ftp_connect($ftp_server); if(!$conn) { exit("Could not connect to server: $ftp_server\n"); } if(!ftp_login($conn,$ftp_user_name,$ftp_user_pass)) { ftp_quit($conn); exit("Could not log in\n"); } ftp_chdir($conn,$ftp_path); $remotefile = "".$date."-".$zipfile.""; if(!ftp_put($conn, $ftp_path.$remotefile, $filename2, FTP_BINARY)) { echo "Could not upload $filename2\n"; } ftp_quit($conn); echo "<h4><center>$filename2 Was created and uploaded to your FTP server!</center></h4>"; } if($remove_file=="yes"){ exec("rm -r -f $filename2"); } ?> Quote
TCH-Bruce Posted December 16, 2006 Posted December 16, 2006 This has been tested on several servers but it looks like the backup zip file is not being created. Have you looked in your backups folder? did the file get created? Second, you are trying to zip your entire public_html folder and email it. That is not recommended as the file is going to become very large depending on the content of the public_html folder. Check to see if the zip file was created. Second, try a subfolder of your public_html folder (something smaller) and see if you get the same results. If that also fails to create the zip file, please let us know. We may have to get the help desk involved. Quote
TCH-Andy Posted December 16, 2006 Posted December 16, 2006 The error you are getting is because you are trying to run this from a broswer - rather than from a cron job. I would recommend that you move the file to an area outside that visible to the public - such as /home/username/backups And then run it via a cron. The paths are different when you run it from the command line. We could modify it to do that - but personally I wouldn't want anyone visiting my site to be able to hit the backup button - so I'd password protect it to say the least I'll go and have a look at what our instructions said, and clarify the issue of running it as a cron job. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.