Ciao, non so se può esserti utile ma io per fare il backup dei db utilizzo questa procedura troata su qsto forum. Il file db.inc contiene i dati per la connessione al database mentre $name è il nome del file che viene creato
require("db.inc");
$now=date("Y-m-d_H:i:s");
$name =$database."_".$now.".sql";
$link = @mysql_connect($host, $db_user, $db_password) or die ("connessione fallita") ;
@mysql_select_db($database) or die ("selezione db non riuscita");
//ho selezionato il db
//codice per il backup
$_PVTVARS['sql_backup'] = "";
$query_sql = "SHOW TABLE STATUS;";
$query=mysql_query($query_sql);
$_PVTVARS['sql_backup'] .= "#################################\n";
$_PVTVARS['sql_backup'] .= "# Backup di $name #\n";
$_PVTVARS['sql_backup'] .= "#################################\n";
$_PVTVARS['sql_backup'] .= "#\n";
$_PVTVARS['sql_backup'] .= "# Backup del " . date ("d_m_Y") . "\n";
$_PVTVARS['sql_backup'] .= "#\n";
$_PVTVARS['sql_backup'] .= "\n";
$_PVTVARS['sql_backup'] .= "\n";
while ($result=mysql_fetch_row($query)) {
$result2=mysql_fetch_array(mysql_query("SHOW CREATE TABLE {$result[0]};"));
$_TABLE['name']=$result[0];
$_TABLE['query']=ereg_replace("[\n]*","",$result2[1]);
$_PVTVARS['sql_backup'] .= "#\n";
$_PVTVARS['sql_backup'] .= "# Drop table, if exists, {$_TABLE['name']} and recreate it\n";
//$_PVTVARS['sql_backup'] .= "#\n";
$_PVTVARS['sql_backup'] .= "DROP TABLE IF EXISTS {$_TABLE['name']};\n";
$_PVTVARS['sql_backup'] .= "{$_TABLE['query']};\n\n";
$_PVTVARS['sql_backup'] .= "#\n";
$_PVTVARS['sql_backup'] .= "# Insert statament for {$_TABLE['name']}\n";
$_PVTVARS['sql_backup'] .= "#\n";
$query_sql2="SELECT * FROM {$_TABLE['name']};";
$query2=mysql_query($query_sql2);
while ($result2=mysql_fetch_row($query2)) {
$_PVTVARS['sql_backup'] .= "INSERT INTO {$_TABLE['name']} VALUES (";
$_INSERT = array();
while (list($key,$value)=each($result2)) {
$value=str_replace("#","",$value);
$value=str_replace("--","--",$value);
//$value=str_replace("\"","\"",$value);
$value=str_replace("'","\'",$value);
$_INSERT[] = "'{$value}'";
}
$_PVTVARS['sql_backup'] .= implode(",",$_INSERT);
$_PVTVARS['sql_backup'] .= ");\n";
}
}
if(ereg("MSIE ([0-9].[0-9]{1,2})", $_SERVER["HTTP_USER_AGENT"])) {
header("Content-Type: application/octetstream");
header("Content-Disposition: inline; filename=$name");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
} else {
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$name");
header("Expires: 0");
header("Pragma: no-cache");
}
//echo implode("",$_PVTVARS['sql_backup']);
echo "",$_PVTVARS['sql_backup'];

Rispondi quotando