<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[在win2003下MySQL数据库每天自动备份]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[数据库技术]]></category>
<pubDate>Tue, 05 Dec 2006 03:17:35 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	终于让服务器每天早上备份一次 MySQL 数据库并自动打包,同时删除 5 天前的备份文件. 分享如下. <br/><br/>1. 环境: windows server 2003 + Apache 2.0 + PHP5 + MySQL 4.0.26 . <br/><br/>2. 假设 PHP 安装目录为 D:/php ,MySQL 安装目录为 D:/mysql. <br/><br/>3. 在 D:/php 下建立目录 WinRAR, 把你 winrar 安装目录下的 WinRAR.exe 和 RARReg.KEY 复制到 D:/php/WinRAR . <br/><br/>4. D:/php 下建立文件 mysql_backup.php: <br/><br/><br/><div class="code"><br/><br/>/*///////////////////////// <br/>#FileName: mysql_backup.php <br/>#Author: faisun <br/>#Website: http://www.softpure.com <br/>////////////////////////*/ &nbsp; &nbsp;<br/>//保存目录,路径要用反斜杠.您需要手动建立它. <br/>$store_folder = &#039;D:&#92;databse_backup&#039;; <br/>//用户名和密码 <br/>//该帐号须有操作&#91;所有&#93;的数据库及FILE的权限 <br/>//否则有些数据库不能备份. <br/>$db_username = &quot;root&quot;; <br/>$db_password = &quot;&quot;; <br/>$time=time(); <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;n&quot;); <br/>@mkdir($nowdir); <br/>mysql_connect(&quot;localhost&quot;,&quot;$db_username&quot;,&quot;$db_password&quot;); <br/>$query=mysql_list_dbs(); <br/>while($result=mysql_fetch_array($query))&#123; <br/>system (dirname(__FILE__).&#039;&#92;..&#92;mysql&#92;bin&#92;mysqldump --opt &#039;.&quot;$result&#91;Database&#93;<br/>-u&#123;$db_username&#125; &quot;.($db_password?&quot;-p&#123;$db_password&#125;&quot;:&quot;&quot;).&quot; &gt;<br/>$nowdir&#92;&#92;$result&#91;Database&#93;.sql&quot;); <br/>echo &quot;dumping database `$result&#91;Database&#93;`...&#92;n&quot;; <br/>&#125; <br/>echo &quot;&#92;nWinrar loading...&#92;n&quot;; <br/>system( dirname(__FILE__).&quot;&#92;&#92;WinRAR&#92;&#92;WinRAR.exe a -ep1 -r -o+ -m5 -df &#92;&quot;$nowdir.rar&#92;&quot; <br/>&quot;$nowdir&#92;&quot; &quot; ); <br/>//删除 5 天前的文件 <br/>@unlink(&quot;$store_folder&#92;&#92;&quot;.date(&quot;Ymd&quot;,$time-86400*5).&quot;.rar&quot;); <br/>echo &quot;&#92;nOK!&#92;n&quot;; <br/>&gt; <br/><br/></div><br/><br/>5. D:/php 下建立文件 mysql_backup.bat,内容只有一句: <br/><br/><div class="code"><br/><br/>php.exe mysql_backup.php <br/><br/></div><br/><br/>6. 双击该 bat 文件运行,如果能备份了,OK,下一步添加任务计划. <br/><br/>7. 把 D:/php/mysql_backup 添加到任务计划,时间选每天. 根据服务器的监测结果,每天早上 5-8 时为流量低峰期. 由于 5-7 时有些数据库的清理工作,可以把时间定在了早上 8 点整.<br/><br/><br/>Tags - <a href="http://www.dzhope.com/tags/mysql/" rel="tag">mysql</a> , <a href="http://www.dzhope.com/tags/%25E6%2595%25B0%25E6%258D%25AE%25E5%25BA%2593%25E5%25A4%2587%25E4%25BB%25BD/" rel="tag">数据库备份</a> , <a href="http://www.dzhope.com/tags/php/" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#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.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>