Mysql Database backup using php Script



You can use php script to take backup of the database with the help of mysqldump.

<?php

public static function BackupDatabase($backupPath){
        
$fileName uniqid() .'.sql';
        
$backupCommand 'mysqldump -u ' DBUsername ' abc &gt; ' $backupPath $fileName .' 2&gt;&amp;1'  ;
        echo 
$backupCommand;
        
$retVal '';
        
$feedback system($backupCommand$retVal);
        echo 
$retVal;
        if(
$feedback == NULL || $feedback == '')
            return 
'Database backed up successfully by name ' $fileName;
        else
            return 
$feedback;
    }
?>