Hi all

Is there a script that can create a full backup of a MySQL database or table like phpMyAdmin does it?

Thanks very much for info. 🙂
Josh

    check phpclasses.org or write your own.

    PHPmyadmin just reads the database and writes a file full of INSERTs.

      found this one on another forum:

      <?php
      /*
      * Backup script
      *
      * Runs on the server, maybe called by Cron.
      * Connects to the mySQL database and echo's the backup of the whole database.
      *
      * @author Gussy <angus@habnetwork.com>
      * @date 01/03/2005
      */
      
      set_time_limit(0);
      
      // Database Variables
      $dbserver = "";
      $dbuser = "";
      $dbpass = "";
      $dbname = "";
      
      mysql_connect ($dbserver, $dbuser, $dbpass);
      mysql_select_db($dbname);
      
      $header_text = "# Angus' Cool SQL Dump\n";
      $header_text .= "#\n";
      $header_text .= "# Host: localhost\n";
      $header_text .= "# Generation Time: ".date('M d, Y \a\t H:i A')."\n";
      $header_text .= "# PHP Version: ".phpversion()."\n";
      $header_text .= "#\n";
      $header_text .= "# Database : `".$dbname."`\n";
      $header_text .= "# \n";
      
      echo($header_text);
      
      $tables = mysql_query ("SHOW TABLES");
      
      while ($i = mysql_fetch_array($tables)) {
          $i = $i['Tables_in_'.$dbname];
      
      // Create DB code
      $create = mysql_fetch_array(mysql_query ("SHOW CREATE TABLE ".$i));
      echo("\n# -------------------------------------------------------- \n");
      echo("\n# \n# Table structure for table `".$create['Table']."` \n# \n");
      
      echo("\n".$create['Create Table'].";\n\n");
      
      echo("# \n# Dumping data for table `".$create['Table']."` \n# \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)."'";
              }
      
              echo("INSERT INTO $i VALUES(".implode(",", $row).");\n");
          }    
      }
      }
      ?> 

      have fun! 🙂

        the best one in my opinion is to invoke mysqldump command from php/otherwise like via cron...

        see the docs of mysqldump

          Write a Reply...