<?php
// function: backup database
// author: windlike.cublog.cn
// create time: 2007.10.05
// config
$dbhost = "localhost";
$dbuser = "root";
$dbpsw = "123456";
$dbname = "bank";
// check folder
$path = getenv('DOCUMENT_ROOT')."/DB_Backup_".$dbname;
if(! file_exists($path)){
mkdir($path);
}
// query
mysql_connect($dbhost, $dbuser, $dbpsw);
mysql_select_db($dbname);
$result = mysql_query("SHOW TABLES");
$numrow = mysql_num_rows($result);
echo "<b>Database [<font color='blue'>$dbname</font>] backup begin ...</b><br>\n\n";
echo "<hr size='1'>\n\n";
echo "<ol>\n";
for($i = 0;$i < $numrow;$i++) {
$table = mysql_result($result,$i);
echo "<li>$table ... ";
system(sprintf("mysqldump --opt -h $dbhost -u $dbuser -p$dbpsw $dbname $table > %s/$table.sql",$path));
//system(sprintf("mysqldump --opt -h $dbhost -u $dbuser -p$dbpsw $dbname $table | gzip > %s/$table.sql.gz",$path));
echo "<font color='red'>done</font></li>\n";
}
echo "</ol>";
?>
|