Help with MySQL dump
Posted: Tue Jun 06, 2006 2:20 pm
I've found this script somewhere on the net, and can't figure it out how to make it work on local machine.
Here is code
Here is code
Code: Select all
<?php
//Full Source at http://www.ov-m.com/mysqlphpbak/
$MYSQL_SERVER="localhost"; // server name
$MYSQL_USER="root"; // authorized mysql user
$MYSQL_PASSWD=""; // authorized user password
$PATHTOMYSQLDUMP="C:/mysql/bin/"; // path to mysqldump utility
$DIRNAME="../backup/"; // where to do the backups
$DIRNAME.=date("dmY"); // add date identifier
$DIRNAME.="/"; // add trailing slash
echo "Creating New Back Up Directory<br><br>";
echo "Using Directory : $DIRNAME<br>";
if (@mkdir ($DIRNAME,0700)) {
echo "New Directory Created<br>";
} else {
echo "Directory already exists!";
}
echo "Backing Up all Databases on $HOSTNAMEnn";
//***************************************************************************
mysql_connect($MYSQL_SERVER,$MYSQL_USER,$MYSQL_PASSWD);
$result = mysql_list_dbs();
$i = 0;
while ($i < mysql_num_rows ($result)) {
$tb_names[$i] = mysql_tablename ($result, $i);
$i++;
}
//***************************************************************************
// Loop through the table names, and do the dump.
//***************************************************************************
for ($i=0; $i<count($tb_names); $i++) {
$COMMAND_DO=$PATHTOMYSQLDUMP. "mysqldump -h ".$MYSQL_SERVER." -u ".$MYSQL_USER." -p ".$MYSQL_PASSWD." ".$tb_names[$i]." > ".$DIRNAME.$tb_names[$i].".sql";
echo $COMMAND_DO . "<br>"; // uncomment these lines if you want to see all
flush(); // back-ups made on the server
exec($COMMAND_DO); // execute each backup
}
echo "nnDONE!n";
?>