właśnie w tym problem że w necie nic nie ma ;d ogólnie poszukiwałem takowych rozwiązań ;d ale ni ma a 2 problem to ze crontab to u mnie czarna magia troche
---edit--- właściwie sam mam kod który robi bacupa bazy danych ale za cuda nie znam funkcji która plik xxx.sql by wgrywala
CODE-BOX
<?phpclass backup_mysql{
function connect($host,$user,$pw,$db){
$this->host=$host;
$this->db=$db;
mysql_connect($host,$user,$pw);
mysql_select_db($db);
$this->con=1;
}
function close(){
mysql_close();
}
function dump_head(){
if($this->con){
return "-- phpSQL Dump
-- version 1.0
-- Host: ".$this->host."
-- Czas wygenerowania: ".date("d. M Y")." um ".date("H:i")."
-- Wersja serwera: ".mysql_get_server_info()."
-- Wersja PHP: ".phpversion()."
--
-- Baza danych:: `".$this->db."`
-- ";
}
else{
die("Brak połączenia z MYSQL");
}
}
function set_drop_table($typ){
$this->drop_table=$typ;
}
function inserts($table){
$str ="\n\n--
-- Zrzut danych tabeli `".$table."`
-- \n";
$get=mysql_query("SELECT * FROM ".$table);
while($row = @mysql_fetch_row($get)){
$str .="INSERT INTO `".$table."` VALUES (";
$count=count($row);
$i=1;
foreach($row as $feld){
if(!is_numeric($feld)) $str .="'".mysql_escape_string($feld)."'";
else $str .=$feld;
if($i<$count) $str .=", ";
$i++;
}
$str .=");\n";
}
return $str;
}
function get_db(){
$get=mysql_list_tables($this->db);
$str=$this->dump_head();
while($table = mysql_fetch_row($get)){
$str.=$this->create_table($table[0]);
$str.=$this->inserts($table[0]);
}
return $str;
}
function create_table($table){
$get_columns = mysql_query("SHOW COLUMNS FROM $table");
$str="\n\n-- --------------------------------------------------------
--
-- Struktura tabeli dla `".$table."`
-- \n";
if($this->drop_table=1) $str.="DROP TABLE IF EXISTS `".$table."`;\n";
$str .="CREATE TABLE `".$table."` (\n";
$count=@mysql_num_rows($get_columns);
$i=1;
$primID="";
$keys=array();
while ($feld = @mysql_fetch_assoc($get_columns)) {
//print_r($feld);
$str .="`".$feld["Field"]."` ".$feld["Type"]."";
if($feld["Null"]!="YES" || $feld['Default']=="CURRENT_TIMESTAMP") $str .=" NOT NULL";
else $str .=" NULL";
if($feld["Default"]!="CURRENT_TIMESTAMP" && !empty($feld["Default"])) $str.=" default '".$feld["Default"]."'";
if($feld["Key"]){
$keys[]=array("typ"=>$feld["Key"], "feld"=>$feld["Field"]);
}
$str .=" ".$feld["Extra"];
if($i<$count || $keys) $str .=",";
else $str .="";
$str .="\n";
$i++;
}
//print_r($keys);
$key_count=count($keys);
$i=1;
//echo $key_count;
$pre_str="PRIMARY KEY (";
foreach($keys as $key){
if($i<$key_count || $pre_str_show==true) $kom=",";
else $kom="";
if($key["typ"]=="PRI"){
if($pre_str_show==true)$pre_str.=", ";
$pre_str.="`".$key["feld"]."`";
$res=mysql_query("SELECT max($key[feld]) as maxid FROM ".$table);
$row = @mysql_fetch_array($res);
$autinc.=" AUTO_INCREMENT=".($row['maxid']+1);
$pre_str_show=true;
}
elseif($key["typ"]=="UNI"){
$str.="UNIQUE KEY `".$key["feld"]."` (`".$key["feld"]."`)".$kom;
}
else{
$str.="KEY `".$key["feld"]."` (`".$key["feld"]."`)".$kom;
}
$str.="\n";
$i++;
}
$pre_str.=")\n";
if($pre_str_show==true)$str.=$pre_str;
$str .=") ENGINE=MyISAM".$autinc." ;";
return $str;
}
}
?>