Auto backup, Ver 1.3

自動備份的php腳本Auto backup, Ver 1.3

<?php /* * Backup script on server. * * Runs on the server, called by Cron. Connects to the mySQL * database and creates a backup file of the whole database. * Saves to file in current directory. * * @author Cow <[email protected]> * @version 0.2 * @date 18/08/2004 * @package Backup Server */   set_time_limit(0);   $dbserver = "localhost"; $dbuser = "dbusername"; $dbpass = "dbpassword"; $dbname = "dbname"; $file = "backup.sql.gz"; $gzip = TRUE; $silent = TRUE;   function write($contents) {   if ($GLOBALS['gzip']) {      gzwrite($GLOBALS['fp'], $contents);   } else {      fwrite($GLOBALS['fp'], $contents);   } }   mysql_connect ($dbserver, $dbuser, $dbpass); mysql_select_db($dbname);   if ($gzip) {   $fp = gzopen($file, "w"); } else {   $fp = fopen($file, "w"); }   $tables = mysql_query ("SHOW TABLES"); while ($i = mysql_fetch_array($tables)) {   $i = $i['Tables_in_'.$dbname];     if (!$silent) {      echo "Backing up table ".$i."/n";   }     // Create DB code   $create = mysql_fetch_array(mysql_query ("SHOW CREATE TABLE ".$i));     write($create['Create Table'].";/n/n");     // DB Table content itself   $sql = mysql_query ("SELECT * FROM ".$i);   if (mysql_num_rows($sql)) {      while ($row = mysql_fetch_row($sql)) {         foreach ($row as $j => $k) {            $row[$j] = "'".mysql_escape_string($k)."'";         }           write("INSERT INTO $i VALUES(".implode(",", $row).");/n");      }   } }   $gzip ? gzclose($fp) : fclose ($fp);   // Fini ?> <script type="text/javascript">document.write('
');</script>
發佈了17 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章