Forum Moderators: coopster
Thanks in advance.
function makeBackup() {
global $username, $password, $database;
$BackupFile = './micropower.' . date('d-m-y') . '.backup.sql';
$BackupCommand = 'mysqldump --compact --user=' . $username . ' --password=' . $password . ' --add-drop-table ' . $database . ' > ' . $BackupFile;
if(file_exists($BackupFile)) {return false;}
else{exec($BackupCommand);
return true;
}
}
function restoreBackup() {
global $username, $password, $database;
$BackupFile = 'micropower.' . date('d-m-y') . '.backup.sql';
$myFile = "{$BackupFile}";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $restoreCommand = "mysql -u {$username} -p{$password} {$database} < {$BackupFile}";
if (exec($restoreCommand)) {return true;}
else {return false;}
}
EDIT: Just tried to import the sql file to see if it works, but for some reason, it stops on double quotes ("). Is there a way to backslash those in the mysqldump (makeBackup)?