Hi guys, hope this is the right place to post this....
I am relatively new to ZC and cronjobs too, and php for that matter. I found a nice php script that compresses the database files and emails them to a specified address. I have uploaded the script and it works by typing the URL path of the script into a browser - the script is then executed and I receive a backup file to the email address I specified.
The problem is when I setup a cronjob through my hosts cPanel - the cronjob goes off at 3am everymorning but it returns an error:
it can obviously see the script file as it is quoting particular lines but I don't know why it wont work, can anyone shed any light for me? (the file has permissions set to 755 as specified where I got the script from).Code:/home/noahsark/public_html/directory/email_backup.php: line 1: ?: No such file or directory /home/noahsark/public_html/directory/email_backup.php: line 2: syntax error near unexpected token `(' /home/noahsark/public_html/directory/email_backup.php: line 2: `$datestamp = date("Y-m-d"); // Current date to append to filename of backup file in format of YYYY-MM-DD'
here is the script:
Code:<? $datestamp = date("Y-m-d"); // Current date to append to filename of backup file in format of YYYY-MM-DD /* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */ $dbuser = "username"; // Database username $dbpwd = "password"; // Database password $dbname = "--all-databases"; // Database name. Use --all-databases if you have more than one $filename= "backup_noahsark_all_databases-$datestamp.sql.gz"; // The name (and optionally path) of the dump file $to = "[email protected]"; // Email address to send dump file to $from = "[email protected]"; // Email address message will show as coming from. $subject = "MySQL backup file"; // Subject of email $command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename"; $result = passthru($command); $attachmentname = array_pop(explode("/", $filename)); // If a path was included, strip it out for the attachment name $message = "Compressed database backup file $attachmentname attached."; $mime_boundary = "<<<:" . md5(time()); $data = chunk_split(base64_encode(implode("", file($filename)))); $headers = "From: $from\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: multipart/mixed;\r\n"; $headers .= " boundary=\"".$mime_boundary."\"\r\n"; $content = "This is a multi-part message in MIME format.\r\n\r\n"; $content.= "--".$mime_boundary."\r\n"; $content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $content.= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $content.= $message."\r\n"; $content.= "--".$mime_boundary."\r\n"; $content.= "Content-Disposition: attachment;\r\n"; $content.= "Content-Type: application/x-gzip; name=\"$attachmentname\"\r\n"; $content.= "Content-Transfer-Encoding: base64\r\n\r\n"; $content.= $data."\r\n"; $content.= "--" . $mime_boundary . "\r\n"; mail($to, $subject, $content, $headers); unlink($filename); //delete the backup file from the server ?>




