I am using Amazon Web Services to run a virtual machine with a Centos image. This machine is a dedicated MySQl server. I am using php script to backup my databases. I am running php in terminal. The script is generating errors that are beyond my scope of knowledge. I desperately need help.
[php]<?php
$emailaddress = “email.domain.com”;
$host = “INTERNAL_IP”; // database host
$dbuser = “db_id”; // database user name
$dbpswd = “db_pswd “; // database password
$mysqldb = “schema”; // name of database
$path = “/home/ec2-user/Backup”; // full server path to backup files directory
// backup database & Compress backup files
$filename = “/home/ec2-user/Backup” . $day . “.sql.gz”;
if ( file_exists($filename) ) unlink($filename);
system(”/usr/bin/mysqldump --user=$dbuser --password=$dbpswd --host=$host $mysqldb > $filename”,$result);
//formate file sizes
$size = filesize($filename);
switch ($size) {
case ($size>=1048576): $size = round($size/1048576) . " MB"; break;
case ($size>=1024): $size = round($size/1024) . " KB"; break;
default: $size = $size . " bytes"; break;
}
//Backup complete messages
$message = “The database backup for " . $mysqldb . " has been run.\n\n”;
$message .= "The return code was: " . $result . “\n\n”;
$message .= "The file path is: " . $filename . “\n\n”;
$message .= “Size of the backup: " . $size . “\n\n”;
$message .= “Server time of the backup: " . date(” F d h:ia”) . “\n\n”;
mail($emailaddress, “Database Backup Message” , $message, “From: Website <>”);
?>
[/php]
Results:
: No such file or directory?php
./SD_DBbackup.php: line 2: =: command not found
: command not foundline 2:
./SD_DBbackup.php: line 3: =: command not found
./SD_DBbackup.php: line 3: //: is a directory
./SD_DBbackup.php: line 4: =: command not found
./SD_DBbackup.php: line 4: //: is a directory
./SD_DBbackup.php: line 5: =: command not found
./SD_DBbackup.php: line 5: //: is a directory
./SD_DBbackup.php: line 6: =: command not found
./SD_DBbackup.php: line 6: //: is a directory
./SD_DBbackup.php: line 7: =: command not found
./SD_DBbackup.php: line 7: //: is a directory
./SD_DBbackup.php: line 8: //: is a directory
./SD_DBbackup.php: line 8: Compress: command not found
./SD_DBbackup.php: line 9: =: command not found
./SD_DBbackup.php: line 9:
./SD_DBbackup.php: line 10: syntax error near unexpected token $filename' ./SD_DBbackup.php: line 10:
if (file_exists($filename) ) unlink($filename);