MySQL dump pakket
Jeg har fundet mig et lille script som laver en backup af min mysql database, men filen fylder 7.5 MB den kan pakket ned til 250-300 Kb, er der en der kan hjælpe mig med at få den til at pakke den fil med det samme, her mener jeg mens den laver en backup.dump.php
<head>
<meta name="ROBOTS" content="noINDEX, noFOLLOW">
<title>MySQL Backupmodul by Transatlantic-Web</title>
</head>
<?php
/*******************************************/
/* MySQL Datenbankbackup */
/* Modul "dump.php" */
/* Version 1.0 , GNU TAW24 Germany */
/* Author Transatlantic-Web */
/* http://www.taw24.de */
/* */
/* modified by benjamin klatt */
/* <benjamin.klatt@raytion.com> */
/*******************************************/
// -------------------------------------------------------------------------------------
include ("dump_cfg.inc");
include ("lang_" .$lang.".inc");
echo "<font size=+1><b>".$title."</b><br>Servername: '".$host."'</font><br>";
echo $system.php_uname().$phpversion.phpversion(). "<p>";
// Alle Datenbanken auf dem Server suchen
echo "<table border=1>";
echo "<tr><td><b>".$dbname."</b></td><td><b>".$tcount."</b></td><td><b>".$size."</b></td><td><b>".$status."</b></td></tr>";
echo "<tr><td> $db1</td>";
$database = $db1;
$zaehler = 0;
$start=0;
// generate filesuffix if it should be used
if($use_date == 1)
{
$datum = "_".date(dmY);
}
else
{
$datum = "";
}
$file_name = $path.$database.$datum.".sql";
$file_old = $path.$database.".old";
$aktime=date("d-m-Y H:i");
$db_name = $dump1."$aktime\n";
$db_name.= $dump2."$database \r\n";
if (file_exists($file_name)){unlink($file_name);}
$fd = fopen($file_name,"a+");
fwrite($fd, $db_name);
fclose($fd);
// Tabellenname Array auslesen und aufbauen
$tbl_array = array(); $c = 0;
$result2 = mysql_list_tables($database);
for($x=0; $x<mysql_num_rows($result2); $x++)
{
$tabelle = mysql_tablename($result2,$x);
if ($tabelle <>"") {
$tbl_array[$c] = mysql_tablename($result2,$x); $c++;$zaehler++;
}
}
echo "<td align=right> ".$zaehler." </td>";
flush();
// Start Ausgabe und Berechnung
for ($y = 0; $y < $c; $y++){
$tabelle=$tbl_array[$y];
// Struktur der Tabelle einlesen
$def = "";
$def .= "DROP TABLE IF EXISTS $tabelle; \n";
$def .= "CREATE TABLE $tabelle (\n";
$result3 = mysql_db_query($database, "SHOW FIELDS FROM $tabelle",$conn_id);
while($row = mysql_fetch_array($result3)) {
$def .= " $row[Field] $row[Type]";
if ($row["Default"] != "") $def .= " DEFAULT '$row[Default]'";
if ($row["Null"] != "YES") $def .= " NOT NULL";
if ($row[Extra] != "") $def .= " $row[Extra]";
$def .= ",\n";
}
$def = ereg_replace(",\n$","", $def);
$result3 = mysql_db_query($database, "SHOW KEYS FROM $tabelle",$conn_id);
while($row = mysql_fetch_array($result3)) {
$kname=$row[Key_name];
if(($kname != "PRIMARY") && ($row[Non_unique] == 0)) $kname="UNIQUE|$kname";
if(!isset($index[$kname])) $index[$kname] = array();
$index[$kname][] = $row[Column_name];
}
while(list($xy, $columns) = @each($index)) {
$def .= ",\n";
if($xy == "PRIMARY") $def .= " PRIMARY KEY (" . implode($columns, ", ") . ")";
else if (substr($xy,0,6) == "UNIQUE") $def .= " UNIQUE ".substr($xy,7)." (" . implode($columns, ", ") . ")";
else $def .= " KEY $xy (" . implode($columns, ", ") . ")";
}
$def .= "\n); \n";
// Ende Struktur Modul
$db = @mysql_select_db($database,$conn_id);
$tabelle="".$tabelle;
$ergebnis=array();
$tbl_name = $dump3."$tabelle \r\n";
$fd = fopen($file_name,"a+");
fwrite($fd, $tbl_name.$def);
fclose($fd);
unset($data);
if ($tabelle>""){
$ergebnis[]=@mysql_select_db($database,$conn_id);
$result=mysql_query("select * from $tabelle");
$anzahl= mysql_num_rows ($result);
$spaltenzahl = mysql_num_fields($result);
for ($i=0;$i<$anzahl;$i++) {
$zeile=mysql_fetch_array($result);
$data.="insert into $tabelle (";
for ($spalte = 0; $spalte < $spaltenzahl;$spalte++) {
$feldname = mysql_field_name($result, $spalte);
if($spalte == ($spaltenzahl - 1))
{
$data.= $feldname;
}
else
{
$data.= $feldname.",";
}
};
$data.=") VALUES (";
for ($k=0;$k < $spaltenzahl;$k++){
if($k == ($spaltenzahl - 1))
{
$data.="'".addslashes($zeile[$k])."'";
}
else
{
$data.="'".addslashes($zeile[$k])."',";
}
}
$data.= ");\n";
}
$data.= "\n";
}
else
{
$ergebnis[]= $err;
}
$zeit = (date("d_m_Y"));
$fd = fopen($file_name,"a+");
$zeit = time() - $start;
$speed = $speed+$zeit;
for ($i3=0;$i3<count($ergebnis);$i3++){
fwrite($fd, $data);
fclose($fd);
}
}
$groesse = filesize($file_name) / 1024;
$place = $place+$groesse;
echo "<td align=right> <I>".number_format($groesse,2)."</I> KB </td><td align=center> OK! </td></tr>";
echo "</table><p>".$info."<I>".$path."<BR>".$allsize.number_format($place,2)."</I> KB <p>";
echo $copyright;
exit;
?>
--------------------------------------
dump_cfg
<?php
/*******************************************/
/* MySQL Datenbankbackup */
/* Modul "dump_cfg.inc" */
/* Version 1.0 , GNU TAW24 Germany */
/* Author Transatlantic-Web */
/* http://www.taw24.de */
/* <info@taw24.de> */
/* */
/* modified by benjamin klatt */
/* <benjamin.klatt@raytion.com> */
/* */
/*******************************************/
// -------------------------------------------------------------------------------------
// Script configuration:
$user = "xxx"; // DB User
$pw = "xxx"; // Passwort
$host = "localhost"; // Hostname
$db1 = "xxx"; // Datenbank
$lang = "de"; // Sprache de / en
$use_date = 0; // Backupdateiname mit Datum versehen 0 = nein / 1 = ja
// -------------------------------------------------------------------------------------
// Don't change the lines below:
$conn_id = mysql_connect($host,$user,$pw) or die(mysql_error());
$path="";
$path = $path . "backup/";
if (!is_dir($path)) mkdir($path, 0777);
?>
---------------------------------
lang_en
<?php
/*******************************************/
/* MySQL Datenbankbackup */
/* Modul "lang_en.inc" */
/* Version 1.0 , GNU TAW24 Germany */
/* Author Transatlantic-Web */
/* http://www.taw24.de */
/*******************************************/
// -------------------------------------------------------------------------------------
// HTML - Ausgabe
$title = "Database Backup (MySQL - DUMP V1.0)";
$system = "Server System: ";
$phpversion= " / PHP - Version: ";
$dbname = "Databasename";
$tcount = "Table Counter";
$size = "Filesize";
$status = "Status";
$err = "No table available";
$info = "Database - Backup OK.<BR>SQL-File directory: /";
$allsize = "Completed Filesize :";
$copyright = "<p> <b>PHP Script written by <a href=http://www.taw24.de>Transatlantic-Web</a>, 2002</b> <p>";
// Dump - File
$dump1 = "# Backup created by Transatlantic-Web at ";
$dump2 = "# Database: ";
$dump3 = "# Tablename: ";
?>
----------------------------------
Jeg havde tænkt mig at droppe de 2 hjælpe filer bare for at ryde lidt op i det, da jeg kun vil bruge engelsk.