despejar mysql usando script PHP

// DB connection info
$host
= "";
$user
= "";
$pwd
= "";
$db
= "";
$backup_file
= 'dbname'. date("Y-m-d-H-i-s");

// Connect to database.
try {
$command
= "mysqldump --opt -h $host -u $user -p $pwd dbname > $backup_file.sql";
exec($command);
}
catch(Exception $e){
die(var_dump($e));
}