Backupdatei anlegen $cur_time=date("Y-m-d H:i"); $newfile="# Dump created on $cur_time\r\n"; $newfile.="# Remember that you must use my restorescript in order to get a working DB\r\n"; $newfile.="# because I use a special code to mark the end of a command.\r\n"; $newfile.="# This is NOT compatible with other restorescripts!\r\n"; $newfile.="# Anyway, have fun with this but use it at your own risk. :-) \r\n"; if ($compression==1) { $fp = gzopen ($path.$backupdatei,"wb"); gzwrite ($fp,$newfile); gzclose ($fp); chmod($path.$backupdatei,0777); } else { $fp = fopen ($path.$backupdatei,"wb"); fwrite ($fp,$newfile); fclose ($fp); chmod($path.$backupdatei,0777); } } $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error()); $tabellen = mysql_list_tables($dbname,$conn); $num_tables = @mysql_num_rows($tabellen); $tables=ARRAY(); if ($num_tables>0) { for ($i=0;$i<$num_tables;$i++) { $erg=mysql_fetch_row($tabellen); $tables[$i]=$erg[0]; } } else die ("
Fehler:
Ich konnte keine Tabellen in der Datenbank '".$dbname."' finden."); ///////////////////////////////// // Anzeige - Fortschritt ///////////////////////////////// echo "\nMySql - DB-Restore\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; $newfile=""; if ($table_offset < $num_tables) { $table = $tables[$table_offset]; $aktuelle_tabelle=$table_offset; if ($zeilen_offset==0) { $newfile .= get_def($dbname,$table); } $newfile .= get_content($dbname,$table); } if ($compression==1) { $fp = gzopen ($path.$backupdatei,"ab"); gzwrite ($fp,$newfile); gzclose ($fp); } else { $fp = fopen ($path.$backupdatei,"ab"); fwrite ($fp,$newfile); fclose ($fp); } if ($table_offset<$num_tables) { // Selbstaufruf starten echo "\n\n\n\n"; } else { if ($send_mail==1) { $msg_body = "\n\r\n\rIn der Anlage findest Du die Sicherung Deiner MySQL-Datenbank.\n\r" ." Sicherung der Datenbank '".$dbname."' vom ".date("d\.m\.Y",time()) .".\n\r\n\rViele Grüsse\n\r\n\rMySQLDump\n\rhttp://www.daniel-schlichtholz.de/board"; $file = "./$path/$backupdatei"; $folder = $path; $fname = $backupdatei; $file_type = filetype("$file"); $file_size = filesize("$file"); $file_name = "$fname"; $subject = "Backup '".$dbname."' - ".date("d\.m\.Y",time()); $fp = fopen($file, "r"); $contents = fread($fp, $file_size); $encoded_file = chunk_split(base64_encode($contents)); fclose($fp); $header.= "FROM:$email[1] <$email[0]>\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/plain; charset=US-ASCII\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_name\"\n"; $msg_body.= "Content-Transfer-Encoding: BASE64\n"; $msg_body.= "Content-disposition: attachment; filename=\"$file_name\"\n\n"; $msg_body.= "$encoded_file\n"; $msg_body.= "--Message-Boundary--\n"; mail($email[0], stripslashes($subject), $msg_body, $header); } } echo "\n\n\n\n"; ?>