<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[虫虫的blog  SINCE2004]]></title> 
<link>http://www.zhenghe.biz/index.php</link> 
<description><![CDATA[人生幻灯片  -   前半生(身)，不要怕；后半生(身)，不要悔！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[虫虫的blog  SINCE2004]]></copyright>
<item>
<link>http://www.zhenghe.biz/read.php/.htm</link>
<title><![CDATA[win2003 下实现 mysql 数据库每天自动备份]]></title> 
<author>网络毛毛虫 &lt;admin@yourname.com&gt;</author>
<category><![CDATA[技术文章]]></category>
<pubDate>Fri, 11 May 2007 09:55:22 +0000</pubDate> 
<guid>http://www.zhenghe.biz/read.php/.htm</guid> 
<description>
<![CDATA[ 
	1. 环境: windows server 2003 + PHP5 + MySQL 5.1.6. <br />2. 假设 PHP 安装目录为 D:/php ,MySQL 安装目录为 D:/mysql. <br />3. 在 D:/php 下建立目录 WinRAR, 把你 winrar 安装目录下的 WinRAR.exe 和 RARReg.KEY 复制到 D:/php/WinRAR . <br />4. D:/php 下建立文件 mysql_backup.php: <br />代码如下: <br /><div class="quote"><div class="quote-title">引用</div><div class="quote-content">&lt;? <br />//保存目录,路径要用反斜杠.您需要手动建立它. <br />$store_folder = 'D:&#92;databse_backup'; <br /><br />//用户名和密码 <br />//该帐号须有操作[所有]的数据库及FILE的权限 <br />//否则有些数据库不能备份. <br />$db_username = &quot;root&quot;; <br />$db_password = &quot;&quot;; <br /><br />$time=time(); <br /><br />$nowdir = &quot;$store_folder&#92;&#92;&quot;.date(&quot;Ymd&quot;,$time).&quot;&quot;; <br />if(file_exists(&quot;$nowdir.rar&quot;)) die(&quot;File exists.&#92;r&#92;n&quot;); <br />@mkdir($nowdir); <br /><br />mysql_connect(&quot;localhost&quot;,&quot;$db_username&quot;,&quot;$db_password&quot;); <br />$query=mysql_list_dbs(); <br /><br /><br />$command = ''; <br />while($result=mysql_fetch_array($query))&#123; <br />$command .= dirname(__FILE__).'&#92;..&#92;mysql&#92;bin&#92;mysqldump --opt '.&quot;$result[Database] -u&#123;$db_username&#125; &quot;.($db_password?&quot;-p&#123;$db_password&#125;&quot;:&quot;&quot;).&quot; &gt; $nowdir&#92;&#92;$result[Database].sql &#92;r&#92;n&quot;; <br />$command .= &quot;echo dumping database `$result[Database]`... &#92;r&#92;n&quot;; <br />&#125; <br />$command .= &quot;echo Winrar loading...&#92;r&#92;n&quot;; <br /><br />$command .= dirname(__FILE__).&quot;&#92;&#92;WinRAR&#92;&#92;WinRAR.exe a -ep1 -r -o+ -m5 -df &#92;&quot;$nowdir.rar&#92;&quot; &#92;&quot;$nowdir&#92;&quot; &#92;r&#92;n&quot;; <br /><br />$command .= &quot;echo OK!&#92;r&#92;n&quot;; <br /><br />$command .= &quot;del mysqldumping_temp.bat&#92;r&#92;n&quot;; <br /><br />$fp = fopen('mysqldumping_temp.bat','w'); <br />fwrite($fp,$command); <br />fclose($fp); <br /><br /><br />//删除 5 天前的文件 <br />@unlink(&quot;$store_folder&#92;&#92;&quot;.date(&quot;Ymd&quot;,$time-86400*5).&quot;.rar&quot;); <br />?&gt; <!-- &nbsp;//保存目录,路径要用反斜杠.您需要手动建立它. &nbsp; &nbsp;$store_folder = 'D:&#92;databse_backup'; &nbsp; &nbsp; &nbsp;//用户名和密码 &nbsp; &nbsp;//该帐号须有操作[所有]的数据库及FILE的权限 &nbsp; &nbsp;//否则有些数据库不能备份. &nbsp; &nbsp;$db_username = "root"; &nbsp; &nbsp;$db_password = ""; &nbsp; &nbsp; &nbsp;$time=time(); &nbsp; &nbsp; &nbsp;$nowdir = "$store_folder&#92;&#92;".date("Ymd",$time).""; &nbsp; &nbsp;if(file_exists("$nowdir.rar")) die("File exists.&#92;r&#92;n"); &nbsp; &nbsp;@mkdir($nowdir); &nbsp; &nbsp; &nbsp;mysql_connect("localhost","$db_username","$db_password"); &nbsp; &nbsp;$query=mysql_list_dbs(); &nbsp; &nbsp; &nbsp; &nbsp;$command = ''; &nbsp; &nbsp;while($result=mysql_fetch_array($query))&#123; &nbsp; &nbsp; &nbsp; &nbsp;$command .= dirname(__FILE__).'&#92;..&#92;mysql&#92;bin&#92;mysqldump --opt '."$result[Database] -u&#123;$db_username&#125; ".($db_password?"-p&#123;$db_password&#125;":"")." > $nowdir&#92;&#92;$result[Database].sql &#92;r&#92;n"; &nbsp; &nbsp; &nbsp; &nbsp;$command .= "echo dumping database `$result[Database]`... &#92;r&#92;n"; &nbsp; &nbsp;&#125; &nbsp; &nbsp; &nbsp; &nbsp;$command .= "echo Winrar loading...&#92;r&#92;n"; &nbsp; &nbsp; &nbsp;$command .= dirname(__FILE__)."&#92;&#92;WinRAR&#92;&#92;WinRAR.exe a -ep1 -r -o+ -m5 -df &#92;"$nowdir.rar&#92;" &#92;"$nowdir&#92;" &#92;r&#92;n"; &nbsp; &nbsp; &nbsp;$command .= "echo OK!&#92;r&#92;n"; &nbsp; &nbsp; &nbsp;$command .= "del mysqldumping_temp.bat&#92;r&#92;n"; &nbsp; &nbsp; &nbsp;$fp = fopen('mysqldumping_temp.bat','w'); &nbsp; &nbsp;fwrite($fp,$command); &nbsp; &nbsp;fclose($fp); &nbsp; &nbsp; &nbsp; &nbsp;//删除 5 天前的文件 &nbsp; &nbsp;@unlink("$store_folder&#92;&#92;".date("Ymd",$time-86400*5).".rar"); &nbsp; --></div></div><br /><br />5. D:/php 下建立文件 mysql_backup.bat,内容为: <br /><span style="color: purple">echo off <br />php.exe mysql_backup.php <br />if exist mysqldumping_temp.bat call mysqldumping_temp.bat</span><br /><br />6. 双击该 bat 文件运行,如果能备份了,OK,下一步添加任务计划. <br />7. 把 D:/php/mysql_backup 添加到任务计划,时间选每天. 根据服务器的监测结果,每天早上 5-8 时为流量低峰期. 由于 5-7 时有些数据库的清理工作,我把时间定在了早上 8 点整.<br /><br/>Tags - <a href="http://www.zhenghe.biz/go.php/tags/win2003/" rel="tag">win2003</a> , <a href="http://www.zhenghe.biz/go.php/tags/mysql/" rel="tag">mysql</a> , <a href="http://www.zhenghe.biz/go.php/tags/%25E4%25BB%25BB%25E5%258A%25A1%25E8%25AE%25A1%25E5%2588%2592/" rel="tag">任务计划</a> , <a href="http://www.zhenghe.biz/go.php/tags/%25E8%2587%25AA%25E5%258A%25A8/" rel="tag">自动</a> , <a href="http://www.zhenghe.biz/go.php/tags/%25E5%25A4%2587%25E4%25BB%25BD/" rel="tag">备份</a>
]]>
</description>
</item><item>
<link>http://www.zhenghe.biz/read.php/.htm#blogcomment</link>
<title><![CDATA[[评论] win2003 下实现 mysql 数据库每天自动备份]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.zhenghe.biz/read.php/.htm#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>