php数据库备份参考,php数据库备份参考
【 tulaoshi.com - PHP 】
转自:http://www1.blog.163.com/article/-Bov-01EjrIa.html<?php
set_time_limit(36000);
$orders = 9; //目标表序号
$dbNames = array("seeditbbs","seedblog"); //备份多库
$con = mysql_connect("localhost","root","h67g4n9s8l"); //h67g4n9s8l
mysql_select_db("seeditbbs",$con);
$rs = mysql_query("SHOW GLOBAL VARIABLES"); //读取MYSQL系统变量 while($row = mysql_fetch_row($rs)){ if($row[0]=="datadir"){
$dataDir = $row[1]; //得到MYSQL的DATA目录
mysql_free_result($rs);
break;}
} foreach($dbNames as $dbName){ //循环备份多库 $fromDir = $dataDir; $toDir = "i:/db_bak/{$dbName}{$orders}/"; //目标目录 if(!is_dir($toDir)) mkdir($toDir ); //建保存目录 $fromDir .= "{$dbName}/"; //源目录 $dirArr = scandir($fromDir);
foreach($dirArr as $subFile){ //拷备所有表文件
if(!@preg_match("|^.+$|",$subFile)) copy($fromDir.$subFile,$toDir.$subFile);
} } ($orders<9) ? $orders++ : $orders=1; //表序号自增,一日9次,备份时间: 1 8 10 12 14 16 18 20 22 $file = file_get_contents($_SERVER["SCRIPT_FILENAME"]);
$file = preg_replace("|$orders = d+|","$orders = $orders",$file); //修改本文件目标表序号 file_put_contents($_SERVER["SCRIPT_FILENAME"],$file); //保存?
来源:http://www.tulaoshi.com/n/20160129/1491768.html