|
|
|
รบกวนแนะนำการทำแบ็คอัพฐานข้อมูลด้วย PHP ไม่เคยทำมาก่อนช่วยแหนะด้วยค๊ะ |
|
|
|
|
|
|
|
1
$dbhost = 'localhost:3036';
$dbuser = 'xxx';
$dbpass = 'xxx';
$backup_file = 'file_name.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass "."my_database | gzip > $backup_file";
system($command);
2
$table_name = "employee";
$backup_file = "/table/employee.sql";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";
mysql_query( $sql, $conn );
|
ประวัติการแก้ไข 2013-06-07 05:53:58
|
|
|
|
Date :
2013-06-07 05:53:35 |
By :
t-monroe |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
back up ออกมาเป็น folder เลย ก้อตามนี้ครับ
Code (PHP)
<?
$datenow= date('y-m-d');
//$filees = 'D:/xampp/mysql/data/'."$dbname";
$filees = 'D:/AppServ/MySQL/data/'."$dbname";
//$fileback = 'D:/xampp/mysql/data/DatabaseAllBackup/'."$dbname";
$fileback = 'D:/AppServ/MySQL/data/DatabaseAllBackup/'."$dbname";
copydir("$filees","$fileback$datenow");
$databasebackup="$dbname$datenow";
$sql = "SELECT ( SELECT COUNT(*) FROM billhead ) AS count1, ( SELECT COUNT(*) FROM billdetail ) AS count2,( SELECT COUNT(*) FROM billspecial) AS count3,( SELECT COUNT(*) FROM paymentdetail ) AS count4,( SELECT COUNT(*) FROM discountdetail) AS count5";
$res = mysql_query($sql,$conn) or die(mysql_error());
$row = mysql_fetch_array($res);
$count1=$row["count1"];
$count2=$row["count2"];
$count3=$row["count3"];
$count4=$row["count4"];
$count5=$row["count5"];
//echo "$dbname///$count1,$count2,$count3,$count4,$count5<p>";
mysql_select_db("$databasebackup");
$sql2 = "SELECT ( SELECT COUNT(*) FROM billhead ) AS countback1, ( SELECT COUNT(*) FROM billdetail ) AS countback2,( SELECT COUNT(*) FROM billspecial) AS countback3,( SELECT COUNT(*) FROM paymentdetail ) AS countback4,( SELECT COUNT(*) FROM discountdetail) AS countback5";
$res2 = mysql_query($sql2, $conn) or die(mysql_error());
$row2 = mysql_fetch_array($res2);
$countback1=$row2["countback1"];
$countback2=$row2["countback2"];
$countback3=$row2["countback3"];
$countback4=$row2["countback4"];
$countback5=$row2["countback5"];
if($count1 == $countback1 and $count2 == $countback2 and $count3 == $countback3 and $count4 == $countback4 and $count5 == $countback5){
$delete='Yes';
}else{
$delete='No';
}
function copydir($source,$destination)
{
if(!is_dir($destination)){
$oldumask = umask(0);
mkdir($destination, 01777); // so you get the sticky bit set
umask($oldumask);
}
$dir_handle = @opendir($source) or die("Not Found Folder BackUp <a href='start.php'>Back</a>");
while ($file = readdir($dir_handle))
{
if($file!="." && $file!=".." && !is_dir("$source/$file"))
copy("$source/$file","$destination/$file");
}
closedir($dir_handle);
}
?>
|
|
|
|
|
Date :
2013-06-07 23:23:01 |
By :
champkung226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|