".$lang['startdump']."`".$databases["Name"][$dump["dbindex"]]."`".(($databases["praefix"][$dump["dbindex"]]!="") ?' ('.$lang["withpraefix"].' '.$databases["praefix"][$dump["dbindex"]].')' : '')."... ";
ExecuteCommand("b");
if($dump["part"]==1) {
$dump["table_offset"]=0;
$dump["countdata"]=0;
}
// Seitenerstaufruf -> Backupdatei anlegen
$dump["data"]=$statuszeile.$mysql_commentstring.' Dump created at '.$cur_time.$nl.$nl;
$dump["structure"]="$mysql_commentstring Status:0:0::".$databases["Name"][$dump["dbindex"]];
$dump["structure"].=":php:".MSD_VERSION.$nl;
$dump["structure"].="$mysql_commentstring Dump by MySQLDump ".MSD_VERSION." (".$config["homepage"].")".$nl;
$dump["structure"].="$mysql_commentstring Dump created on ".$cur_time.$nl."$mysql_commentstring This file is only the structure of the database without data \n\n";
}
else
{
if($config["multi_part"]!=0) {
WriteLog("Continue Multipart-Dump with File ".($dump["part"]-$dump["part_offset"])." (last file was $last_groesse Bytes)");
$dump["data"]=$statuszeile.$mysql_commentstring.' This is part '.($dump["part"]-$dump["part_offset"]).' of the backup.'.$nl.$nl.$dump["data"];
}
}
WriteToDumpFile();
$dump["part"]++;
}
function GetStatusLine($kind="php")
{
global $databases,$config, $dump,$mysql_commentstring;
$t_array=explode("|",$databases["db_actual_tableselected"]);
$t=0;
$r=0;
$mp="";$t_zeile="$mysql_commentstring\n$mysql_commentstring TABLE-INFO\n";
MSD_mysql_connect();
$res=mysql_query("SHOW TABLE STATUS FROM `".$databases["Name"][$dump["dbindex"]]."`");
$numrows=mysql_num_rows($res);
for($i=0;$i<$numrows;$i++) {
$erg=mysql_fetch_array($res);
if($databases["db_actual_tableselected"]=="" || ($databases["db_actual_tableselected"]!="" && (in_array($erg[0],$t_array)))) {
$t++;$r+=$erg["Rows"];
$t_zeile.="$mysql_commentstring TABLE|".$erg["Name"]."|".$erg["Rows"]."|".($erg["Data_length"]+$erg["Index_length"])."|".$erg["Update_time"]."\n";
}
}
$dump["totalrecords"]=$r;
if($config["multi_part"]==1) $mp="MP_".($dump["part"]-$dump["part_offset"]);
return "$mysql_commentstring Status:$t:$r:$mp:".$databases["Name"][$dump["dbindex"]].":$kind:".MSD_VERSION.":".$dump["kommentar"].":EXTINFO\n".$t_zeile."$mysql_commentstring"."EOF TABLE-INFO\n$mysql_commentstring\n\n";
}
// Liest die Eigenschaften der Tabelle aus der DB und baut die CREATE-Anweisung zusammen
function get_def($db, $table,$withdata=1)
{
global $config,$nl,$mysql_commentstring;
$def = "\n\n$mysql_commentstring\n$mysql_commentstring Create Table `$table`\n$mysql_commentstring\n\nDROP TABLE IF EXISTS `$table`;\n";
mysql_select_db($db);
$result = mysql_query("SHOW CREATE TABLE `$table`",$config["dbconnection"]);
$row=mysql_fetch_row($result);
$def .= (($config["backup_downgrade"]==1) ? DownGrade($row[1],false) : $row[1].";")."\n\n";
if($withdata==1) {
$def.="$mysql_commentstring\n$mysql_commentstring Data for Table `$table`\n$mysql_commentstring\n\n";
if($config["backup_delayed_inserts"]==0) $def.="/*!40000 ALTER TABLE `$table` DISABLE KEYS */;".$nl;
if($config["backup_lock_tables"]==1 && $config["backup_delayed_inserts"]==0) $def.="LOCK TABLES `$table` WRITE;\n\n";
}
return $def;
}
// Liest die Daten aus der DB aus und baut die INSERT-Anweisung zusammen
function get_content($db, $table)
{
global $config,$nl,$dump;
$content="";
$delayed=(isset($config["backup_delayed_inserts"]) && $config["backup_delayed_inserts"]==1) ? "DELAYED " : "";
$complete=(isset($config["backup_complete_inserts"]) && $config["backup_complete_inserts"]==1) ? Fieldlist($db,$table)." " : "";
$ignore=(isset($config["backup_ignore_inserts"]) && $config["backup_ignore_inserts"]==1) ? "IGNORE " : "";
$table_ready=0;
$query="SELECT * FROM `$table` LIMIT ".$dump["zeilen_offset"].",".($dump["restzeilen"]+1);
mysql_select_db($db);
$result = mysql_query($query,$config["dbconnection"]);
$ergebnisse=mysql_num_rows($result);
$first=1;
//$dump["countdata"]+=$ergebnisse;
if ($ergebnisse>$dump["restzeilen"])
{
$dump["zeilen_offset"]+=$dump["restzeilen"];
$ergebnisse--;
$dump["restzeilen"]=0;
}
else
{
$dump["table_offset"]++;
$dump["zeilen_offset"]=0;
$dump["restzeilen"]=$dump["restzeilen"]-$ergebnisse;
$table_ready=1;
}
$ax=0;
for ($x=0;$x<$ergebnisse;$x++)
{
$row=mysql_fetch_row($result);
$ax++;
{
if($config["backup_extended_inserts"]==0 || ($config["backup_extended_inserts"]==1 && $first==1 && $ax==1) ) {
$insert = "INSERT ".$delayed.$ignore."INTO `$table` ".$complete."VALUES (";
$first=0;
} else $insert="(";
$num_felder=mysql_num_fields($result);
for($j=0; $j<$num_felder;$j++)
{
if(!isset($row[$j])) $insert .= "NULL,";
else if($row[$j] != "") $insert .= "'".mysql_escape_string($row[$j])."',";
else $insert .= "'',";
}
$insert = ereg_replace(",$","",$insert);
if(strlen($dump["data"])>400000 || $x==($ergebnisse-1)) {
$ax=0;$first=1;
}
$insert .= ($config["backup_extended_inserts"]==0 || $x==($ergebnisse-1) || $ax==0) ? ");\n" : "),";
$dump["data"] .= $insert;
$dump["countdata"]++;
if(strlen($content)>$config["memory_limit"] || ($config["multi_part"]==1 && strlen($content)>$config["multipart_groesse"]) ) {
WriteToDumpFile();
}
}
}
if($table_ready==1 && $config["backup_lock_tables"]==1 && $config["backup_delayed_inserts"]==0) $dump["data"].="\nUNLOCK TABLES;";
if($table_ready==1 && $config["backup_delayed_inserts"]==0) $dump["data"].="\n/*!40000 ALTER TABLE `$table` ENABLE KEYS */;\n\n";
mysql_free_result($result);
}
function WriteToDumpFile()
{
global $config,$dump;
$dump["filesize"]=0;
$df=$config["paths"]["backup"].$dump["backupdatei"];
$sf=$config["paths"]["structure"].$dump["backupdatei_structure"];
if ($config["compression"]==1)
{
if($dump["data"]!="") {
$fp = gzopen ($df,"ab");
gzwrite ($fp,$dump["data"]); gzclose ($fp);
}
if($dump["structure"]!="") {
$fp = gzopen ($sf,"ab");
gzwrite ($fp,$dump["structure"]); gzclose ($fp);
}
}
else
{
if($dump["data"]!="") {
$fp = fopen ($df,"ab");
fwrite ($fp,$dump["data"]);fclose ($fp);
}
if($dump["structure"]!="") {
$fp = fopen ($sf,"ab");
fwrite ($fp,$dump["structure"]); fclose ($fp);
}
}
$dump["data"]=$dump["structure"]="";
if(!isset($dump["fileoperations"])) $dump["fileoperations"]=0;
$dump["fileoperations"]++;
$dump["filesize"]=filesize($df);
if ($config["multi_part"]==1 && $dump["filesize"]>$config["multipart_groesse"])
new_file($dump["filesize"]); // Wenn maximale Dateigroesse erreicht -> neues File starten
}
function ExecuteCommand($when)
{
global $config,$databases,$dump,$out,$lang;
if($when=="b") { // before dump
$cd=$databases["command_before_dump"][$dump["dbindex"]];
$cap="before Dump"; $lf="
";
} else {
$cd=$databases["command_after_dump"][$dump["dbindex"]];
$cap="after Dump"; $lf="";
}
if($cd!="") {
//jetzt ausführen
if(substr(strtolower($cd),0,7)!="system:") {
@mysql_select_db($databases["Name"][$dump["dbindex"]]);
if(strpos($cd,";")) {
$cad=explode(";",$cd);
for($i=0;$iERROR executing Query '.$cap.'
';
} else {
WriteLog("executing Query $cap ($cd) was successful");
$out.=$lf.'executing Query '.$cap.' was successful
';
}
} elseif(substr(strtolower($cd),0,7)=="system:") {
//$result=@system(substr($cd,7),$returnval);
$cap=substr($cd,7);
$result=1;
if(!$result) {
WriteLog("Error while executing System Command $cap");
$dump["errors"]++;
$out.=$lf.'ERROR executing System Command '.$cap.'
';
} else {
WriteLog("executing System Command $cap was successful. [$returnval]");
$out.=$lf.'executing System Command '.$cap.' was successful
';
}
}
}
}
function DoEmail()
{
global $config,$dump,$databases,$email,$lang,$out,$REMOTE_ADDR;
$header="";
if($config["cron_use_sendmail"]==1) {
//sendmail
if(ini_get("sendmail_path")!=$config["cron_sendmail"]) @ini_set("SMTP",$config["cron_sendmail"]);
if(ini_get("sendmail_from")!=$config["email_sender"]) @ini_set("SMTP",$config["email_sender"]);
} else {
//SMTP
}
if(ini_get("SMTP")!=$config["cron_smtp"]) @ini_set("SMTP",$config["cron_smtp"]);
if(ini_get("smtp_port")!=25) @ini_set("smtp_port",25);
if($config["multi_part"]==0) {
$file = $dump["backupdatei"];
$file_name=(strpos("/",$file)) ? substr($file,strrpos("/",$file)) : $file;
$file_type = filetype($config["paths"]["backup"].$file);
$file_size = filesize($config["paths"]["backup"].$file);
if(($config["email_maxsize"]>0 && $file_size>$config["email_maxsize"]) || $config["send_mail_dump"]==0) {
//anhang zu gross
$subject = "Backup '".$databases["Name"][$dump["dbindex"]]."' - ".date("d\.m\.Y H:i",time());
$header.= "FROM:".$config["email_sender"]."\n";
$header .= "X-Mailer: PHP/" . phpversion(). "\n";
$header .= "X-Sender-IP: $REMOTE_ADDR\n";
$header .= "Content-Type: text/html";
if($config["send_mail_dump"]!=0) {
$msg_body = sprintf($lang["emailbody_toobig"],byte_output($config["email_maxsize"]),$databases["Name"][$dump["dbindex"]],"$file (".byte_output(filesize($config["paths"]["backup"].$file)).")
");
} else {
$msg_body = sprintf($lang["emailbody_noattach"],$databases["Name"][$dump["dbindex"]],"$file (".byte_output(filesize($config["paths"]["backup"].$file)).")");
}
$email_log="Email sent to '".$config["email_recipient"]."'";
$email_out=$lang["email_was_send"]."`".$config["email_recipient"]."`
";
} else {
//alles ok, anhang generieren
$msg_body = sprintf($lang["emailbody_attach"],$databases["Name"][$dump["dbindex"]],"$file (".byte_output(filesize($config["paths"]["backup"].$file)).")");
$subject = "Backup '".$databases["Name"][$dump["dbindex"]]."' - ".date("d\.m\.Y",time());
$fp = fopen($config["paths"]["backup"].$file, "r");
$contents = fread($fp, $file_size);
$encoded_file = chunk_split(base64_encode($contents));
fclose($fp);
$header.= "FROM:".$config["email_sender"]."\n";
$header.= "MIME-version: 1.0\n";
$header.= "Content-type: multipart/mixed; ";
$header.= "boundary=\"Message-Boundary\"\n";
$header.= "Content-transfer-encoding: 7BIT\n";
$header.= "X-attachments: $file_name";
$body_top = "--Message-Boundary\n";
$body_top.= "Content-type: text/html\n";
$body_top.= "Content-transfer-encoding: 7BIT\n";
$body_top.= "Content-description: Mail message body\n\n";
$msg_body = $body_top . $msg_body;
$msg_body.= "\n\n--Message-Boundary\n";
$msg_body.= "Content-type: $file_type; name=\"$file\"\n";
$msg_body.= "Content-Transfer-Encoding: BASE64\n";
$msg_body.= "Content-disposition: attachment; filename=\"$file\"\n\n";
$msg_body.= "$encoded_file\n";
$msg_body.= "--Message-Boundary--\n";
$email_log="Email was sent to '".$config["email_recipient"]."' with '".$dump["backupdatei"]."'.";
$email_out=$lang["email_was_send"]."`".$config["email_recipient"]."`".$lang['with']."`".$dump["backupdatei"]."`.
";
}
} else {
//Multipart
$mp_sub="Backup '".$databases["Name"][$dump["dbindex"]]."' - ".date("d\.m\.Y",time());
$subject = $mp_sub;
$header.= "FROM:".$config["email_sender"]."\n";
$header .= "X-Mailer: PHP/" . phpversion(). "\n";
$header .= "X-Sender-IP: $REMOTE_ADDR\n";
$header .= "Content-Type: text/html";
$dateistamm=substr($dump["backupdatei"],0,strrpos($dump["backupdatei"],"part_"))."part_";
$dateiendung=($config["compression"]==1)?".sql.gz":".sql";
$mpdatei=Array();
$mpfiles="";
for ($i=1;$i<($dump["part"]-$dump["part_offset"]);$i++) {
$mpdatei[$i-1]=$dateistamm.$i.$dateiendung;
$sz=byte_output(@filesize($config["paths"]["backup"].$mpdatei[$i-1]));
$mpfiles.=$mpdatei[$i-1]." (".$sz.")
";
}
$msg_body = ($config["send_mail_dump"]==1) ? sprintf($lang["emailbody_mp_attach"],$databases["Name"][$dump["dbindex"]],$mpfiles) : sprintf($lang["emailbody_mp_noattach"],$databases["Name"][$dump["dbindex"]],$mpfiles);
$email_log="Email was sent to '".$config["email_recipient"]."'";
$email_out=$lang["email_was_send"]."`".$config["email_recipient"]."`
";
}
if (@mail($config["email_recipient"], stripslashes($subject), $msg_body, $header)) {
$out.= ''.$email_out.'';
WriteLog("$email_log");
} else {
$out.=''.$lang["mailerror"].'
';
WriteLog("Email to '".$config["email_recipient"]."' failed !");
ErrorLog("Email ",$databases["Name"][$dump["dbindex"]],'Subject: '.stripslashes($subject),$lang["mailerror"]);
$dump["errors"]++;
}
if(isset($mpdatei) && $config["send_mail_dump"]==1) { // && ($config["email_maxsize"]==0 || ($config["email_maxsize"]>0 && $config["multipartgroesse2"]<=$config["email_maxsize"]))) {
for($i=0;$i";
if (@mail($config["email_recipient"], stripslashes($subject), $msg_body, $header)) {
$out.= ''.$email_out.'';
WriteLog("$email_log");
} else {
$out.=''.$lang["mailerror"].'
';
WriteLog("Email to '".$config["email_recipient"]."' failed !");
ErrorLog("Email ",$databases["Name"][$dump["dbindex"]],'Subject: '.stripslashes($subject),$lang["mailerror"]);
$dump["errors"]++;
}
}
}
}
function DoFTP()
{
global $config,$dump,$out;
if($config["multi_part"]==0) {
SendViaFTP($dump["backupdatei"],1);
} else {
$dateistamm=substr($dump["backupdatei"],0,strrpos($dump["backupdatei"],"part_"))."part_";
$dateiendung=($config["compression"]==1)?".sql.gz":".sql";
for ($i=1;$i<($dump["part"]-$dump["part_offset"]);$i++) {
$mpdatei=$dateistamm.$i.$dateiendung;
SendViaFTP($mpdatei,$i);
}
}
$out.=''."file sent via FTP (".$dump["backupdatei"]." => ".$config["ftp_server"][$config["ftp_connectionindex"]].")
";
}
function SendViaFTP($source_file,$conn_msg=1)
{
global $config,$out,$lang;
flush();
if($conn_msg==1) $out.=''.$lang['filesendftp']."(".$config["ftp_server"][$config["ftp_connectionindex"]]." - ".$config["ftp_user"][$config["ftp_connectionindex"]].")
";
// Herstellen der Basis-Verbindung
if($config["ftp_useSSL"]==0)
$conn_id = ftp_connect($config["ftp_server"][$config["ftp_connectionindex"]], $config["ftp_port"][$config["ftp_connectionindex"]],$config["ftp_timeout"]);
else
$conn_id = ftp_ssl_connect($config["ftp_server"][$config["ftp_connectionindex"]], $config["ftp_port"][$config["ftp_connectionindex"]],$config["ftp_timeout"]);
// Einloggen mit Benutzername und Kennwort
$login_result = ftp_login($conn_id, $config["ftp_user"][$config["ftp_connectionindex"]], $config["ftp_pass"][$config["ftp_connectionindex"]]);
// Verbindung überprüfen
if ((!$conn_id) || (!$login_result)) {
$out.= ''.$lang['ftpconnerror'].$config["ftp_server"][$config["ftp_connectionindex"]].$lang['ftpconnerror1'].$config["ftp_user"][$config["ftp_connectionindex"]].$lang['ftpconnerror2'].'
';
exit;
} else {
if($conn_msg==1) $out.= ''.$lang['ftpconnected1'].$config["ftp_server"][$config["ftp_connectionindex"]].$lang['ftpconnerror1'].$config["ftp_user"][$config["ftp_connectionindex"]].'
';
}
// Upload der Datei
$dest=$config["ftp_dir"][$config["ftp_connectionindex"]].$source_file;
$source=$config["paths"]["backup"].$source_file;
$upload = @ftp_put($conn_id, $dest,$source , FTP_BINARY);
// Upload-Status überprüfen
if (!$upload) {
$out.= ''.$lang['ftpconnerror3']."
($source -> $dest)
";
} else {
$out.= ''.$lang['file'].' '.$source_file.''.$lang['ftpconnected2'].$config["ftp_server"][$config["ftp_connectionindex"]].$lang['ftpconnected3'].'
';
WriteLog("'$source_file' sent via FTP.");
}
// Schließen des FTP-Streams
@ftp_quit($conn_id);
}
?>