Dieser Commit ist enthalten in:
Commit
a4890c2cda
37 geänderte Dateien mit 3387 neuen und 0 gelöschten Zeilen
48
inc/config.php
Normale Datei
48
inc/config.php
Normale Datei
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
//////////////////////////////////////////////////////////
|
||||
// erforderliche Variablen - bitte anpassen
|
||||
// please enter your database-login
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
$dbhost = 'localhost'; // HOST
|
||||
$dbuser = 'root'; // USER
|
||||
$dbpass = ''; // PASSWORD
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// das wars schon - der Rest kann auch innerhalb des Programms ge<67>ndert werden!
|
||||
// that's it - you can change the other values from within the program!
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$lang="de"; // de,en
|
||||
$path="backup/";
|
||||
$compression=1;
|
||||
$send_mail=0;
|
||||
$email[0]="admin@daniel-schlichtholz.de";
|
||||
$email[1]="mein_board@weltweit.de";
|
||||
$ftp_transfer=0;
|
||||
$ftp_server=""; // Adresse des FTP-Servers. z.B. ftp.server.de
|
||||
$ftp_port="21"; // Port des FTP-Servers. z.B. 21
|
||||
$ftp_user=""; // Username
|
||||
$ftp_pass=""; // Passwort
|
||||
$ftp_dir=""; // der Pfad, wohin gesendet werden soll (der user muss in diesem Verzeichnis Upload-Rechte haben)
|
||||
$auto_delete=0;
|
||||
$del_files_after_days=0;
|
||||
$max_backup_files=3;
|
||||
$tabellen_praefix=""; // zum Beispiel /for example "phpBB_"
|
||||
$anzahl_zeilen=2000;
|
||||
$anzahl_zeilen_restore=1000;
|
||||
$cron_timelimit=360;
|
||||
$cron_samedb=0;
|
||||
$cron_dbindex=0;
|
||||
|
||||
// Der "Ende des SQL-Befehls"-Code kann ge<67>ndert werden falls in der Datenbank
|
||||
// zuf<75>llig der angegebene Code vorhanden sein sollte und Du Fehlermeldungen
|
||||
// beim Restore bekommst.
|
||||
// Es muss aber ein eindeutiger String sein, der NICHT in den Daten der DB vorkommt.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// I use this code to mark the end of a sql-line.
|
||||
// If you have problems because you find this string in your database as data you may change it.
|
||||
// But only think of this if you know what you are doing. :-)
|
||||
$next_sqlcommand="[n.!!e_w._!]";
|
||||
|
||||
?>
|
||||
8
inc/footer.php
Normale Datei
8
inc/footer.php
Normale Datei
|
|
@ -0,0 +1,8 @@
|
|||
<br><p align="center" class="small">
|
||||
Idee:
|
||||
<a class="small" href="http://www.daniel-schlichtholz.de" target="_new">
|
||||
Daniel Schlichtholz</a> - Infoboard:
|
||||
<a class="small" href="http://www.daniel-schlichtholz.de/board" target="_new">
|
||||
www.daniel-schlichtholz.de/board</a></p>
|
||||
</BODY>
|
||||
</HTML>
|
||||
399
inc/functions.php
Normale Datei
399
inc/functions.php
Normale Datei
|
|
@ -0,0 +1,399 @@
|
|||
<?php
|
||||
|
||||
$version="0.9.3c";
|
||||
$nl="\n";
|
||||
define ("_DEVELOP_",true);
|
||||
|
||||
//Die Arbeitsverzeichnisse
|
||||
$rootdir=substr($PHP_SELF,0,strrpos($PHP_SELF,"/"));
|
||||
$work="work/";
|
||||
$backup_path=$work."backup/";
|
||||
$structure_path=$work."structure/";
|
||||
$log_path=$work."log/";
|
||||
$log_file=$log_path."mysqldump.log";
|
||||
$config_path=$work."config/";
|
||||
$config_file=$config_path."parameter.php";
|
||||
|
||||
function TestWorkDir()
|
||||
{
|
||||
global $rootdir,$work,$backup_path,$structure_path,$log_path,$log_file,$config_path,$config_file;
|
||||
|
||||
if (!is_dir($work)) {
|
||||
// Arbeitsverzeichnis existiert noch nicht? Na gut, dann machen wir eben eins. :-)
|
||||
mkdir($work, 0777);
|
||||
mkdir($backup_path, 0777);
|
||||
mkdir($structure_path, 0777);
|
||||
mkdir($log_path, 0777);
|
||||
mkdir($config_path, 0777);
|
||||
|
||||
} else {
|
||||
if (!is_dir($backup_path)) mkdir($backup_path, 0777); else {if(decoct(fileperms($backup_path))<>0777)chmod($backup_path, 0777);}
|
||||
if (!is_dir($structure_path)) mkdir($structure_path, 0777); else {if(decoct(fileperms($structure_path)<>0777))chmod($structure_path, 0777);}
|
||||
if (!is_dir($log_path)) mkdir($log_path, 0777); else {if(decoct(fileperms($log_path)<>0777))chmod($log_path, 0777);}
|
||||
if (!is_dir($config_path)) mkdir($config_path, 0777); else {if(decoct(fileperms($config_path)<>0777))chmod($config_path, 0777);}
|
||||
}
|
||||
if(!file_exists($config_file))SetDefault();
|
||||
if(!file_exists($log_file)){DeleteLog();}
|
||||
}
|
||||
|
||||
function Help($ToolTip,$Anker)
|
||||
{
|
||||
global $lang;
|
||||
return '<a href="language/help_'.$lang.'.html#'.$Anker.'"><img src="images/help16.gif" width="16" height="16" alt="'.$ToolTip.'" hspace="4" vspace="0"></a>';
|
||||
}
|
||||
|
||||
function DeleteFiles($dir, $pattern = "*.*")
|
||||
{
|
||||
$deleted = false;
|
||||
$pattern = str_replace(array("\*","\?"), array(".*","."), preg_quote($pattern));
|
||||
if (substr($dir,-1) != "/") $dir.= "/";
|
||||
if (is_dir($dir))
|
||||
{ $d = opendir($dir);
|
||||
while ($file = readdir($d))
|
||||
{ if (is_file($dir.$file) && ereg("^".$pattern."$", $file))
|
||||
{ if (unlink($dir.$file)) $deleted[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($d);
|
||||
return $deleted;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
function SelectDB($index)
|
||||
{
|
||||
global $dbname,$dbpraefix, $dbname_a, $dbpraefix_a,$db_selected_index;
|
||||
|
||||
$dbname = $dbname_a[$index];
|
||||
$dbpraefix = $dbpraefix_a[$index];
|
||||
$db_selected_index=$index;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function SetDefault($dbonly=false)
|
||||
{
|
||||
global $dbhost,$dbname,$dbuser,$dbpass, $dbpraefix, $compression,$send_mail,$email,$nl,
|
||||
$anzahl_zeilen,$anzahl_zeilen_restore,$tabellen_praefix,$next_sqlcommand,
|
||||
$dbhost_a, $dbname_a, $dbuser_a, $dbpass_a, $dbpraefix_a, $db_selected_index, $lang,
|
||||
$auto_delete, $del_files_after_days, $max_backup_files,
|
||||
$cron_timelimit,$cron_samedb,$cron_dbindex, $l,
|
||||
$rootdir,$work,$backup_path,$structure_path,$log_path,$config_path,$config_file;
|
||||
|
||||
|
||||
if($dbonly==false){
|
||||
@unlink($config_file);
|
||||
include("inc/config.php");
|
||||
}
|
||||
//Arrays löschen
|
||||
$i=0;
|
||||
$dbname_a=Array();
|
||||
//DB-Liste holen
|
||||
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error().$l["wrong_userpass"]);
|
||||
$db_list = mysql_list_dbs($conn);
|
||||
while ($row = mysql_fetch_object($db_list))
|
||||
{
|
||||
$found_db=$row->Database;
|
||||
$cnt=mysql_list_tables($found_db,$conn);
|
||||
if($cnt!=NULL){
|
||||
$dbname_a[$i++]=$found_db;
|
||||
$out.=$l["saving_db_form"]." ".$found_db." ($cnt) ".$l["added"]."$nl";
|
||||
}
|
||||
}
|
||||
$dbname=$dbname_a[0];
|
||||
|
||||
//SelectDB(0);
|
||||
WriteParams();
|
||||
|
||||
if($dbonly==false) WriteLog("default settings loaded.");
|
||||
return $out;
|
||||
}
|
||||
|
||||
function WriteParams()
|
||||
{
|
||||
global $dbhost,$dbname,$dbuser,$dbpass, $dbpraefix, $dbcronpraefix, $compression,$send_mail,$email,$nl,
|
||||
$anzahl_zeilen,$anzahl_zeilen_restore,$next_sqlcommand,
|
||||
$dbhost_a, $dbname_a, $dbuser_a, $dbpass_a, $dbpraefix_a, $db_selected_index, $lang,
|
||||
$auto_delete, $del_files_after_days, $max_backup_files,
|
||||
$cron_timelimit,$cron_samedb,$cron_dbindex,
|
||||
$ftp_transfer, $ftp_server, $ftp_port, $ftp_user, $ftp_pass, $ftp_dir,
|
||||
$rootdir,$work,$backup_path,$structure_path,$log_path,$config_path,$config_file;
|
||||
|
||||
//Parameter überprüfen und gegebenfalls auf Standardwerte setzen
|
||||
if(!isset($anzahl_zeilen))$anzahl_zeilen=2000;
|
||||
if(!isset($anzahl_zeilen_restore))$anzahl_zeilen_restore=1000;
|
||||
if(!isset($del_files_after_days))$del_files_after_days=0;
|
||||
if(!isset($max_backup_files))$max_backup_files=0;
|
||||
if(!isset($cron_timelimit))$cron_timelimit=360;
|
||||
if(!isset($ftp_port))$ftp_port=21;
|
||||
|
||||
|
||||
//Parameter zusammensetzen
|
||||
$param='<?php '.$nl;
|
||||
if (!isset($db_selected_index)) $db_selected_index=0;
|
||||
|
||||
$param.='$db_selected_index='.$db_selected_index.';'.$nl;
|
||||
$param.='$dbhost="'.$dbhost.'";'.$nl;
|
||||
$param.='$dbname="'.$dbname.'";'.$nl;
|
||||
$param.='$dbuser="'.$dbuser.'";'.$nl;
|
||||
$param.='$dbpass="'.$dbpass.'";'.$nl;
|
||||
|
||||
for($i=0;$i<count($dbname_a);$i++)
|
||||
{
|
||||
$param.='$dbname_a['.$i.']="'.$dbname_a[$i].'";'.$nl;
|
||||
$param.='$dbpraefix_a['.$i.']="'.$dbpraefix_a[$i].'";'.$nl;
|
||||
}
|
||||
//$param.='$path="'.$path.'";'.$nl;
|
||||
$param.='$compression='.$compression.';'.$nl;
|
||||
if (!isset($send_mail)) $send_mail=0;
|
||||
$param.='$send_mail='.$send_mail.';'.$nl;
|
||||
$param.='$email[0]="'.$email[0].'";'.$nl;
|
||||
$param.='$email[1]="'.$email[1].'";'.$nl;
|
||||
|
||||
$param.='$auto_delete='.$auto_delete.';'.$nl;
|
||||
$param.='$del_files_after_days='.$del_files_after_days.';'.$nl;
|
||||
$param.='$max_backup_files='.$max_backup_files.';'.$nl;
|
||||
|
||||
$param.=(strlen($next_sqlcommand)==1) ? '$next_sqlcommand=CHR('.ord($next_sqlcommand).');'.$nl :'$next_sqlcommand="'.$next_sqlcommand.'";'.$nl;
|
||||
$param.='$anzahl_zeilen='.$anzahl_zeilen.';'.$nl;
|
||||
$param.='$anzahl_zeilen_restore='.$anzahl_zeilen_restore.';'.$nl;
|
||||
$param.='$lang="'.$lang.'";'.$nl;
|
||||
$param.='$dbpraefix="'.$dbpraefix.'";'.$nl;
|
||||
$param.='$dbcronpraefix="'.$dbcronpraefix.'";'.$nl;
|
||||
$param.='$cron_timelimit='.$cron_timelimit.';'.$nl;
|
||||
$param.='$cron_samedb='.$cron_samedb.';'.$nl;
|
||||
$param.='$cron_dbindex='.$cron_dbindex.';'.$nl;
|
||||
$param.='$ftp_transfer="'.$ftp_transfer.'";'.$nl;
|
||||
$param.='$ftp_server="'.$ftp_server.'";'.$nl;
|
||||
$param.='$ftp_port="'.$ftp_port.'";'.$nl;
|
||||
$param.='$ftp_user="'.$ftp_user.'";'.$nl;
|
||||
$param.='$ftp_pass="'.$ftp_pass.'";'.$nl;
|
||||
$param.='$ftp_dir="'.$ftp_dir.'";'.$nl;
|
||||
|
||||
$param.='// Sprachfile laden'.$nl.'include("language/lang_'.$lang.'.php")'.$nl;;
|
||||
$param.='?>';
|
||||
|
||||
|
||||
//Datei öffnen und schreiben
|
||||
$ret=true;
|
||||
|
||||
if ($fp=fopen($config_file, "wb"))
|
||||
{
|
||||
if (!fwrite($fp,$param)) $ret=false;
|
||||
if (!fclose($fp)) $ret=false;
|
||||
}
|
||||
else $ret=false;
|
||||
$ret=WriteCronScript();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function AutoDelete()
|
||||
{
|
||||
global $del_files, $max_backup_files, $del_files_after_days, $l,
|
||||
$rootdir,$work,$backup_path,$structure_path,$log_path,$config_path,$config_file;
|
||||
|
||||
$dh = opendir($backup_path);
|
||||
while (false !== ($filename = readdir($dh)))
|
||||
{
|
||||
if ($filename != "." && $filename != "..") {
|
||||
$z=substr($filename,strpos($filename,".")-2);
|
||||
$z=substr($z,6,4).substr($z,3,2).substr($z,0,2).substr($z,11,2).substr($z,18,2);
|
||||
$files[] = $z."|".$filename;
|
||||
}
|
||||
}
|
||||
|
||||
@rsort($files);
|
||||
|
||||
// Mehr Dateien vorhanden, als es laut config.php sein dürften? Dann weg damit :-)
|
||||
if($max_backup_files > 0)
|
||||
{
|
||||
if (sizeof($files) > $max_backup_files)
|
||||
{
|
||||
$out.="<font color=\"red\">".$l["fm_autodel1"]."<br>";
|
||||
for($n=sizeof($files)-1; $n>=$max_backup_files; $n--)
|
||||
{
|
||||
$delfile=substr($files[$n],13);
|
||||
$out.= $backup_path.$delfile."<br>";
|
||||
WriteLog("autodeleted (max)'$delfile'.");
|
||||
unlink($backup_path.$delfile);
|
||||
}
|
||||
$out.= "</font>";
|
||||
}
|
||||
}
|
||||
|
||||
if($del_files_after_days>0) {
|
||||
//neu einlesen
|
||||
$dh = opendir($backup_path);
|
||||
$nowtime=strtotime("-".($del_files_after_days+1)." day");
|
||||
$zout="<font color=\"red\">".$l["fm_autodel2"]."<br>";
|
||||
$dfad=false;
|
||||
while (false !== ($filename = readdir($dh)))
|
||||
{
|
||||
if ($filename != "." && $filename != "..") {
|
||||
$z=substr($filename,strpos($filename,".")-2);
|
||||
$z=substr($z,6,4)."-".substr($z,3,2)."-".substr($z,0,2);
|
||||
if(strtotime($z)<$nowtime){
|
||||
$out.= $backup_path.$filename."<br>";
|
||||
WriteLog("autodeleted (days)'$delfile'.");
|
||||
unlink($backup_path.$filename);
|
||||
$dfad=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$zout.= "</font>";
|
||||
if($dfad) $out.=$outz;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
function WriteLog($aktion)
|
||||
{
|
||||
global $log_file;
|
||||
//Zeile zusammensetzen
|
||||
$log=date("d.m.Y h:i:s").': '.$aktion."\n";
|
||||
//Datei öffnen und schreiben
|
||||
$fp = fopen($log_file, "a+");
|
||||
fwrite ($fp,($log));
|
||||
fclose ($fp);
|
||||
}
|
||||
|
||||
function DeleteLog()
|
||||
{
|
||||
global $log_file;
|
||||
//Datei öffnen und schreiben
|
||||
$log=date("d.m.Y h:i:s").": Log created.\n";
|
||||
$fp = fopen($log_file, "wb");
|
||||
fwrite ($fp,$log);
|
||||
fclose ($fp);
|
||||
}
|
||||
|
||||
function WriteCronScript()
|
||||
{
|
||||
|
||||
global $nl, $config_path,$dbname,$dbname_a,$dbcronpraefix,$cron_samedb,
|
||||
$dbuser,$dbpass,$compression,$backup_path,$log_file,$rootdir,$cron_dbindex;
|
||||
|
||||
if($cron_samedb==0) {
|
||||
$cron_dbname=$dbname;
|
||||
$cron_dbpraefix = $dbpraefix;
|
||||
}else {
|
||||
$cron_dbname=$dbname_a[$cron_dbindex];
|
||||
$cron_dbpraefix = $dbcronpraefix;
|
||||
}
|
||||
|
||||
$p1=$_SERVER["DOCUMENT_ROOT"].'/'.substr($rootdir,1).'/'.$backup_path;
|
||||
$p2=$_SERVER["DOCUMENT_ROOT"].'/'.substr($rootdir,1).'/'.$log_file;
|
||||
|
||||
if(substr($p1,1,1)==":"){
|
||||
$p1=str_replace("/","\\\\",$p1);
|
||||
$p2=str_replace("/","\\\\",$p2);
|
||||
}
|
||||
|
||||
|
||||
$cronscript='#!/usr/bin/perl -w';
|
||||
$cronscript.='##################################################'.$nl;
|
||||
$cronscript.='# MySQLDump CronDump'.$nl;
|
||||
$cronscript.='# 2004, Steffen Kamper'.$nl;
|
||||
$cronscript.='##################################################'.$nl;
|
||||
$cronscript.='use DBI;'.$nl;
|
||||
$cronscript.='use Compress::Zlib ;'.$nl;
|
||||
$cronscript.='# Parameter'.$nl.$nl;
|
||||
|
||||
$cronscript.='my $dbname="'.$cron_dbname.'";'.$nl;
|
||||
$cronscript.='my $dbpraefix="'.$dbcronpraefix.'";'.$nl;
|
||||
$cronscript.='my $dbuser="'.$dbuser.'";'.$nl;
|
||||
$cronscript.='my $dbpass="'.$dbpass.'";'.$nl;
|
||||
$cronscript.='my $compression='.$compression.';'.$nl;
|
||||
$cronscript.='my $backup_path="'.$p1.'";'.$nl;
|
||||
$cronscript.='my $logdatei="'.$p2.'";'.$nl.$nl;
|
||||
|
||||
$cronscript.='($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time);'.$nl;
|
||||
$cronscript.='$Jahr+=1900;'.$nl;
|
||||
$cronscript.='my $CTIME_String = localtime(time);'.$nl;
|
||||
$cronscript.='$time_stamp=sprintf("%02d",$Monatstag).".".sprintf("%02d",$Monat).".".$Jahr."_".sprintf("%02d",$Stunden)."_Uhr_".sprintf("%02d",$Minuten);'.$nl;
|
||||
$cronscript.='$sql_file=$backup_path.$dbname."_".$time_stamp."_crondump_perl.sql";'.$nl;
|
||||
$cronscript.='$sql_file_z=$backup_path.$dbname."_".$time_stamp."_crondump_perl.sql.gz";'.$nl;
|
||||
$cronscript.='$dt=sprintf("%02d",$Monatstag).".".sprintf("%02d",$Monat).".".$Jahr." ". sprintf("%02d",$Stunden).":".sprintf("%02d",$Minuten).":".sprintf("%02d",$Sekunden).": ";'.$nl;
|
||||
$cronscript.='if($compression==0){$dt.="Start Perl Cron-Dump \'$sql_file\'\n";}else{$dt.="Start Perl Cron-Dump \'$sql_file_z\' \n";}'.$nl;
|
||||
$cronscript.='open(DATEI,">>$logdatei");'.$nl;
|
||||
$cronscript.='print DATEI $dt;'.$nl;
|
||||
$cronscript.='close(DATEI);'.$nl;
|
||||
$cronscript.='open(DATEI,">$sql_file");'.$nl;
|
||||
$cronscript.='print DATEI "";'.$nl;
|
||||
$cronscript.='close(DATEI);'.$nl;
|
||||
|
||||
$cronscript.='# Verbindung mit mSQL herstellen, $dbh ist das Database Handle'.$nl;
|
||||
$cronscript.='my $dbh = DBI->connect("DBI:mysql:".$dbname,$dbuser,$dbpass)|| die "Database connection not made: $DBI::errstr";'.$nl;
|
||||
$cronscript.='my $nl="\n";'.$nl;
|
||||
$cronscript.='my $next_sqlcommand="[n.!!e_w._!]";'.$nl;
|
||||
$cronscript.='my $sql_text="# Dump created on $CTIME_String by PERL Cron-Script\n";'.$nl;
|
||||
$cronscript.='$sql_text.="# Remember that you must use my restorescript in order to get a working DB\n";'.$nl;
|
||||
$cronscript.='$sql_text.="# because I use a special code to mark the end of a command.\n";'.$nl;
|
||||
$cronscript.='$sql_text.="# This is NOT compatible with other restorescripts!\n";'.$nl;
|
||||
$cronscript.='$sql_text.="# Anyway, have fun with this but use it at your own risk. :-)\n";'.$nl;
|
||||
$cronscript.='@tables=$dbh->tables;'.$nl;
|
||||
$cronscript.='foreach $tabelle (@tables) {'.$nl;
|
||||
$cronscript.='# definition auslesen'.$nl;
|
||||
$cronscript.='if($dbpraefix eq "" or ($dbpraefix ne "" && substr($tabelle,0,length($dbpraefix)) eq $dbpraefix)) {'.$nl;
|
||||
$cronscript.='$a="DROP TABLE IF EXISTS `".$tabelle."`;".$next_sqlcommand."\n";'.$nl;
|
||||
$cronscript.='$sql_text.=$a;'.$nl;
|
||||
$cronscript.='$sql_create="Show create table `".$tabelle."`";'.$nl;
|
||||
$cronscript.='$sth = $dbh->prepare($sql_create);'.$nl;
|
||||
$cronscript.='$sth->execute;'.$nl;
|
||||
$cronscript.='@ergebnis=$sth->fetchrow;'.$nl;
|
||||
$cronscript.='$sth->finish;'.$nl;
|
||||
$cronscript.='$a=$ergebnis[1].";".$next_sqlcommand."\n";'.$nl;
|
||||
$cronscript.='$sql_text.=$a;'.$nl;
|
||||
$cronscript.='# daten auslesen'.$nl;
|
||||
$cronscript.='$insert = "INSERT INTO `$tabelle` VALUES (";'.$nl;
|
||||
$cronscript.='$sql_daten="SELECT * FROM `".$tabelle."`";'.$nl;
|
||||
$cronscript.='$sth = $dbh->prepare($sql_daten);'.$nl;
|
||||
$cronscript.='$sth->execute;'.$nl;
|
||||
$cronscript.='while ( @ar=$sth->fetchrow)'.$nl;
|
||||
$cronscript.='{'.$nl;
|
||||
$cronscript.='$a=$insert;'.$nl;
|
||||
$cronscript.='foreach $inhalt(@ar)'.$nl;
|
||||
$cronscript.='{$a.= $dbh->quote($inhalt).", ";}'.$nl;
|
||||
$cronscript.='$a=substr($a,0, length($a)-2).");";'.$nl;
|
||||
$cronscript.='$sql_text.= $a.$next_sqlcommand."\n";'.$nl;
|
||||
$cronscript.='}#jetzt wegschreiben'.$nl;
|
||||
$cronscript.='if($compression==0){'.$nl;
|
||||
$cronscript.=' open(DATEI,">>$sql_file");'.$nl;
|
||||
$cronscript.=' print DATEI $sql_text;'.$nl;
|
||||
$cronscript.=' close(DATEI);'.$nl;
|
||||
$cronscript.='} else {'.$nl;
|
||||
$cronscript.='$gz = gzopen($sql_file_z, "wb") or die "Cannot open : $gzerrno\n" ;'.$nl;
|
||||
$cronscript.='$gz->gzwrite($sql_text) or die "error writing: $gzerrno\n" ;'.$nl;
|
||||
$cronscript.='$gz->gzclose ;'.$nl;
|
||||
$cronscript.=' } $sql_text="";'.$nl;
|
||||
$cronscript.='}}# Ende'.$nl;
|
||||
|
||||
$cronscript.='($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time);'.$nl;
|
||||
$cronscript.='$Jahr+=1900;'.$nl;
|
||||
$cronscript.='$dt=sprintf("%02d",$Monatstag).".".sprintf("%02d",$Monat).".".sprintf("%02d",$Jahr)." ".sprintf("%02d",$Stunden).":".sprintf("%02d",$Minuten).":".sprintf("%02d",$Sekunden).": Perl Cron-Dump \'$sql_file\' finished.\n";'.$nl;
|
||||
|
||||
$cronscript.='open(DATEI,">>$logdatei");'.$nl;
|
||||
$cronscript.='print DATEI $dt;'.$nl;
|
||||
$cronscript.='close(DATEI);'.$nl;
|
||||
$cronscript.='$dbh->disconnect();'.$nl;
|
||||
|
||||
//Datei öffnen und schreiben
|
||||
$ret=true;
|
||||
|
||||
if ($fp=fopen($config_path."crondump.pl", "wb"))
|
||||
{
|
||||
if (!fwrite($fp,$cronscript)) $ret=false;
|
||||
if (!fclose($fp)) $ret=false;
|
||||
}
|
||||
|
||||
else $ret=false;
|
||||
chmod($config_path."crondump.pl",0777);
|
||||
return $ret;
|
||||
|
||||
}
|
||||
?>
|
||||
165
inc/functions_dump.php
Normale Datei
165
inc/functions_dump.php
Normale Datei
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
$nl="\n"; // Newline-Code
|
||||
//Die Arbeitsverzeichnisse
|
||||
$rootdir=substr($PHP_SELF,0,strrpos($PHP_SELF,"/"));
|
||||
$work="work/";
|
||||
$backup_path=$work."backup/";
|
||||
$structure_path=$work."structure/";
|
||||
$log_path=$work."log/";
|
||||
$log_file=$log_path."mysqldump.log";
|
||||
$config_path=$work."config/";
|
||||
$config_file=$config_path."parameter.php";
|
||||
|
||||
function TestWorkDir()
|
||||
{
|
||||
global $rootdir,$work,$backup_path,$structure_path,$log_path,$log_file,$config_path,$config_file;
|
||||
|
||||
if (!is_dir($work)) {
|
||||
// Arbeitsverzeichnis existiert noch nicht? Na gut, dann machen wir eben eins. :-)
|
||||
mkdir($work, 0777);
|
||||
mkdir($backup_path, 0777);
|
||||
mkdir($structure_path, 0777);
|
||||
mkdir($log_path, 0777);
|
||||
mkdir($config_path, 0777);
|
||||
|
||||
} else {
|
||||
if (!is_dir($backup_path)) mkdir($backup_path, 0777); else {if(decoct(fileperms($backup_path))<>0777)chmod($backup_path, 0777);}
|
||||
if (!is_dir($structure_path)) mkdir($structure_path, 0777); else {if(decoct(fileperms($structure_path)<>0777))chmod($structure_path, 0777);}
|
||||
if (!is_dir($log_path)) mkdir($log_path, 0777); else {if(decoct(fileperms($log_path)<>0777))chmod($log_path, 0777);}
|
||||
if (!is_dir($config_path)) mkdir($config_path, 0777); else {if(decoct(fileperms($config_path)<>0777))chmod($config_path, 0777);}
|
||||
}
|
||||
if(!file_exists($config_file))SetDefault();
|
||||
if(!file_exists($log_file)){DeleteLog();}
|
||||
}
|
||||
|
||||
// Liest die Eigenschaften der Tabelle aus der DB und baut die CREATE-Anweisung zusammen
|
||||
function get_def($dbname, $table)
|
||||
{
|
||||
global $conn,$nl,$next_sqlcommand;
|
||||
$def = "DROP TABLE IF EXISTS `$table`;".$next_sqlcommand.$nl;
|
||||
$result = mysql_db_query($dbname, "SHOW CREATE TABLE `$table`",$conn);
|
||||
$row=mysql_fetch_row($result);
|
||||
$def .=$row[1].";".$next_sqlcommand.$nl;
|
||||
return $def;
|
||||
}
|
||||
|
||||
|
||||
// Liest die Daten aus der DB aus und baut die INSERT-Anweisung zusammen
|
||||
function get_content($dbname, $table)
|
||||
{
|
||||
global $restzeilen,$conn,$anzahl_zeilen,$table_offset,$zeilen_offset,$nl,$next_sqlcommand, $countdata;
|
||||
|
||||
$content="";
|
||||
|
||||
$query="SELECT * FROM $table LIMIT $zeilen_offset,".($restzeilen+1);
|
||||
$result = mysql_db_query($dbname,$query,$conn);
|
||||
$ergebnisse=mysql_num_rows($result);
|
||||
$countdata+=$ergebnisse;
|
||||
if ($ergebnisse>$restzeilen)
|
||||
{
|
||||
$zeilen_offset=$zeilen_offset+$restzeilen;
|
||||
$ergebnisse--;
|
||||
$countdata--;
|
||||
$restzeilen=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$table_offset++;
|
||||
$zeilen_offset=0;
|
||||
$restzeilen=$restzeilen-$ergebnisse;
|
||||
}
|
||||
for ($x=0;$x<$ergebnisse;$x++)
|
||||
{
|
||||
$row=mysql_fetch_row($result);
|
||||
{
|
||||
|
||||
$insert = "INSERT INTO $table VALUES (";
|
||||
for($j=0; $j<mysql_num_fields($result);$j++)
|
||||
{
|
||||
if(!isset($row[$j])) $insert .= "NULL,";
|
||||
else if($row[$j] != "") $insert .= "'".addslashes($row[$j])."',";
|
||||
else $insert .= "'',";
|
||||
}
|
||||
$insert = ereg_replace(",$","",$insert);
|
||||
$insert .= ");";
|
||||
$content .= $insert.$next_sqlcommand.$nl;
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
function SendViaFTP($source_file)
|
||||
{
|
||||
global $ftp_server, $ftp_port, $ftp_user,$ftp_pass,$ftp_dir,$backup_path;
|
||||
flush();
|
||||
echo "<br><br>versende File via FTP...bitte hab etwas Geduld. ($ftp_server - $ftp_user)<br>";
|
||||
|
||||
|
||||
// Herstellen der Basis-Verbindung
|
||||
$conn_id = ftp_connect($ftp_server, $ftp_port) or die ("<font color=\"#FF0000\">Ftp-Verbindung zum Server $ftp_server nicht möglich!<br></font>");
|
||||
|
||||
// Einloggen mit Benutzername und Kennwort
|
||||
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
|
||||
|
||||
// Verbindung überprüfen
|
||||
if ((!$conn_id) || (!$login_result)) {
|
||||
echo "<font color=\"#FF0000\">Ftp-Verbindung nicht hergestellt!";
|
||||
echo "Verbindung mit $ftp_server als Benutzer $ftp_user nicht möglich</font><br>";
|
||||
die;
|
||||
} else {
|
||||
echo "Verbunden mit $ftp_server als Benutzer $ftp_user<br>";
|
||||
}
|
||||
|
||||
// Upload der Datei
|
||||
$dest=$ftp_dir.$source_file;
|
||||
$source=$backup_path.$source_file;
|
||||
$upload = ftp_put($conn_id, $dest,$source , FTP_BINARY);
|
||||
|
||||
// Upload-Status überprüfen
|
||||
if (!$upload) {
|
||||
echo "<font color=\"#FF0000\">Ftp upload war fehlerhaft! <br>($source -> $dest)</font><br>";
|
||||
} else {
|
||||
echo "Datei $source_file auf $ftp_server als $ftp_dir.$source_file geschrieben<br>";
|
||||
WriteLog("'$backupdatei' sent via FTP.");
|
||||
}
|
||||
|
||||
// Schließen des FTP-Streams
|
||||
ftp_quit($conn_id);
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Kommt aus functions.php
|
||||
/////////////////////////////
|
||||
function SelectDB($index)
|
||||
{
|
||||
global $dbhost,$dbname,$dbuser,$dbpass, $dbpraefix,
|
||||
$dbhost_a, $dbname_a, $dbuser_a, $dbpass_a, $dbpraefix_a;
|
||||
|
||||
$dbhost = $dbhost_a[$index];
|
||||
$dbname = $dbname_a[$index];
|
||||
$dbuser = $dbuser_a[$index];
|
||||
$dbpass = $dbpass_a[$index];
|
||||
$dbpraefix = $dbpraefix_a[$index];
|
||||
}
|
||||
|
||||
function WriteLog($aktion)
|
||||
{
|
||||
global $log_file;
|
||||
//Zeile zusammensetzen
|
||||
$log=date("d.m.Y h:i:s").': '.$aktion."\n";
|
||||
//Datei öffnen und schreiben
|
||||
$fp = fopen($log_file, "a+");
|
||||
fwrite ($fp,($log));
|
||||
fclose ($fp);
|
||||
}
|
||||
function DeleteLog()
|
||||
{
|
||||
global $log_file;
|
||||
//Datei öffnen und schreiben
|
||||
$log=date("d.m.Y h:i:s").": Log created.\n";
|
||||
$fp = fopen($log_file, "wb");
|
||||
fwrite ($fp,$log);
|
||||
fclose ($fp);
|
||||
}
|
||||
|
||||
?>
|
||||
93
inc/functions_restore.php
Normale Datei
93
inc/functions_restore.php
Normale Datei
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
$nl="\n"; // Newline-Code
|
||||
//Die Arbeitsverzeichnisse
|
||||
$rootdir=substr($PHP_SELF,0,strrpos($PHP_SELF,"/"));
|
||||
$work="work/";
|
||||
$backup_path=$work."backup/";
|
||||
$structure_path=$work."structure/";
|
||||
$log_path=$work."log/";
|
||||
$log_file=$log_path."mysqldump.log";
|
||||
$config_path=$work."config/";
|
||||
$config_file=$config_path."parameter.php";
|
||||
////////////////////////////////////
|
||||
// funktion kommt aus functions.php
|
||||
// muss hier aber vorhanden sein
|
||||
////////////////////////////////////
|
||||
function WriteLog($aktion)
|
||||
{
|
||||
global $log_file;
|
||||
//Zeile zusammensetzen
|
||||
$log=date("d.m.Y h:i:s").': '.$aktion."\n";
|
||||
//Datei öffnen und schreiben
|
||||
$fp = fopen($log_file, "a+");
|
||||
fwrite ($fp,($log));
|
||||
fclose ($fp);
|
||||
}
|
||||
|
||||
// Prüft ob es sich um eine Kommentarzeile handelt
|
||||
function is_sqlvalue($t)
|
||||
{
|
||||
// Uebergeht Kommentarzeilen im Dump
|
||||
if ( (strlen($t)>0) && (substr($t,0,1)!="#") ) return $t;
|
||||
else return "";
|
||||
}
|
||||
|
||||
// extrahiert auf einfache Art den Tabellennamen aus dem "Create"-Befehl
|
||||
function get_tablename($t)
|
||||
{
|
||||
global $table_ready;
|
||||
$t=trim(str_replace("CREATE TABLE","",$t));
|
||||
$w=explode(" ",$t);
|
||||
$table_ready++;
|
||||
return $w[0];
|
||||
}
|
||||
|
||||
// Liest zeilenweise aus dem Dump und setzt den MySQl-Befehl
|
||||
// bis zum Vorkommen des Codes [chr(1)] zusammen
|
||||
function get_sqlbefehl()
|
||||
{
|
||||
global $f,$gz,$end,$actual_table,$next_sqlcommand;
|
||||
$ret=false;
|
||||
$befehl="";
|
||||
$befehl_gefunden=false;
|
||||
WHILE ( ($befehl_gefunden==false) && (!($end)) )
|
||||
{
|
||||
$zeile= ($gz) ? gzgets($f,40960) : fgets($f,40960);
|
||||
if ($zeile)
|
||||
{
|
||||
// Prima, wir haben Text in unserer Zeile.
|
||||
// Dann wollen wir den Befehl mal zusammensetzen. :-)
|
||||
|
||||
// Zuerst mal schauen, ob es sich nicht um eine Kommentarzeile handelt
|
||||
// Aber nur am Anfang eines Befehls - sonst besteht die Gefahr, dass
|
||||
// Zeilen in Datensaetzen geloescht werden.
|
||||
if ($befehl=="") $zeile=is_sqlvalue($zeile);
|
||||
|
||||
// Dann schauen wir mal nach dem Ende-Code...
|
||||
$pos=strpos($zeile,$next_sqlcommand);
|
||||
if (!$pos===false)
|
||||
{
|
||||
// Ende des Befehls gefunden - Rueckgabe ohne Semikolon und Ende-Code
|
||||
$befehl.=substr($zeile,0,($pos-1));
|
||||
$befehl_gefunden=true;
|
||||
$ret=$befehl;
|
||||
}
|
||||
// Befehl ist noch nicht fertig: Zeile zum Befehl hinzufuegen
|
||||
else $befehl.=$zeile;
|
||||
|
||||
// Pruefen, ob die naechste Tabelle angelegt wird (nur fuer Infoanzeige)
|
||||
if (strtolower(substr($zeile,0,13))=="create table ") $actual_table=get_tablename($zeile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ups, kein Rueckgabewert in der Zeile?
|
||||
// Ja sind wir denn schon fertig? - Das ueberpruefen wir mal mit eof()...
|
||||
if ( ($gz) && (gzeof($f)) ) $end=true;
|
||||
if ( (!$gz) && (feof($f)) ) $end=true;
|
||||
$ret="end of file";
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
?>
|
||||
13
inc/header.php
Normale Datei
13
inc/header.php
Normale Datei
|
|
@ -0,0 +1,13 @@
|
|||
<html>
|
||||
<head>
|
||||
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
|
||||
<title>MySqlDump</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
</head>
|
||||
<body bgcolor="#F5F5F5">
|
||||
<?php
|
||||
include_once("inc/functions.php");
|
||||
TestWorkDir();
|
||||
include($config_file);
|
||||
SelectDB($db_selected_index);
|
||||
?>
|
||||
110
inc/info.php
Normale Datei
110
inc/info.php
Normale Datei
|
|
@ -0,0 +1,110 @@
|
|||
<?
|
||||
if($_GET["action"]=="phpinfo") {
|
||||
phpinfo();
|
||||
echo '<p align="center"><a href="../index.php">Home</a></p>';
|
||||
die;
|
||||
}
|
||||
|
||||
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error()."");
|
||||
|
||||
if($_GET["action"]=="db") {
|
||||
for($i=0;$i<count($dbname_a);$i++) {
|
||||
if(isset($_POST["empty".$i])) {
|
||||
$res=mysql_query("DROP DATABASE `$dbname_a[$i]`") or die(mysql_error()."");
|
||||
$res=mysql_query("CREATE DATABASE `$dbname_a[$i]`") or die(mysql_error()."");
|
||||
$dba= $l["db"]." $dbname_a[$i] ".$l["info_cleared"]."<br>";
|
||||
break;
|
||||
}
|
||||
if(isset($_POST["kill".$i])) {
|
||||
$res=mysql_query("DROP DATABASE `$dbname_a[$i]`") or die(mysql_error()."");
|
||||
$dba= $l["db"]." $dbname_a[$i] ".$l["info_deleted"]."<br>";
|
||||
SetDefault(true);
|
||||
echo '<script language="JavaScript">parent.menu.location.href="menu.php";</script>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($_GET["action"]=="newdb") {
|
||||
if($_POST["dbneu"]!="" && isset($_POST["submit"])) {
|
||||
$res=mysql_query("CREATE DATABASE `".$_POST["dbneu"]."`") or die(mysql_error()."");
|
||||
$dba=$l["db"]." '".$_POST["dbneu"]."' ".$l["info_created"]."<br>";
|
||||
SetDefault(true);
|
||||
echo '<script language="JavaScript">parent.menu.location.href="menu.php";</script>';
|
||||
}
|
||||
}
|
||||
|
||||
$res=mysql_query("select version()");
|
||||
$row = mysql_fetch_array($res);
|
||||
echo 'PHP-Version: <strong>'.phpversion().'</strong> <a style="text-decoration:underline;" href="inc/info.php?action=phpinfo">[Info]</a><br>';
|
||||
echo 'MySQL-Version: <strong>'.$row[0].'</strong><br>';
|
||||
|
||||
echo $l["info_location"].' "<b>'.$_SERVER["SERVER_NAME"].'</b>" ('.$_SERVER["DOCUMENT_ROOT"].').<br>';
|
||||
|
||||
echo $l["info_workdir"].": <b>$work</b><br>";
|
||||
echo $l["info_backupdir"].": <b>$backup_path</b><br>";
|
||||
echo $l["info_actdb"].":<strong> $dbname</strong><br>";
|
||||
|
||||
echo '<hr><h4>'.$l["info_databases"].'</h4><div style="padding-left:10px; font-weight:bold;">';
|
||||
echo $dba.'<table border="2" cellpadding="2" cellspacing="2" width="70%">';
|
||||
|
||||
for($i=0;$i<count($dbname_a);$i++) {
|
||||
//gibts die Datenbank überhaupt?
|
||||
if (!mysql_select_db($dbname_a[$i],$conn)) {
|
||||
echo '<tr><td>'.$dbname_a[$i].'</td><td colspan="3">'.$l["info_nodb"].'</td>';
|
||||
} else {
|
||||
mysql_select_db($dbname_a[$i],$conn);
|
||||
$tabellen = mysql_list_tables($dbname_a[$i],$conn);
|
||||
$num_tables = mysql_num_rows($tabellen);
|
||||
echo '<tr><td><a style="text-decoration:underline;" href="'.$PHP_SELF.'?dbid='.$i.'">'.$dbname_a[$i].'</a></td>';
|
||||
echo '<td>'.$num_tables.' '.$l["info_table1"];
|
||||
echo ($num_tables>1) ? $l["info_table2"] : '';
|
||||
echo '</td>';
|
||||
|
||||
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
echo '</table>';
|
||||
|
||||
echo '<form action="'.$PHP_SELF.'?action=newdb" method="post"><table border="1"><tr>';
|
||||
echo '<td>'.$l["create_database"].'</td><td><input type="text" name="dbneu" size="23" maxlength="50"></td><td><input class="Formbutton2" type="submit" name="submit" value="'.$l["button_create_database"].'"></td></tr></table></form>';
|
||||
echo '</div>';
|
||||
|
||||
if (isset($_GET["dbid"]))
|
||||
{
|
||||
$dbid=$_GET["dbid"];
|
||||
echo '<hr><h4>'.$l["info_dbdetail"].'"'.$dbname_a[$dbid].'"</h4>';
|
||||
|
||||
$res=mysql_query("SHOW TABLE STATUS FROM ".$dbname_a[$dbid]);
|
||||
$numrows=mysql_num_rows($res);
|
||||
if($numrows==0) {
|
||||
echo $l["info_dbempty"];
|
||||
|
||||
} else {
|
||||
echo $numrows.' '.$l["info_table1"];
|
||||
echo ($numrows>1) ? $l["info_table2"] : '';
|
||||
|
||||
echo '<br><table border="1"><tr><td class="hd">Nr.</td><td class="hd">'.$l["info_table1"].'</td><td class="hd">'.$l["info_records"].'</td><td class="hd">'.$l["info_size"].'</td><td class="hd">'.$l["info_lastupdate"].'</td></tr>';
|
||||
$last_update="2000-01-01 00:00:00";
|
||||
for ($i = 0; $i < $numrows; $i++)
|
||||
{
|
||||
$row = mysql_fetch_array($res);
|
||||
echo '<tr><td align="right">'.($i+1).'</td><td>'.$row[Name].'</td><td align="right">'.number_format($row[Rows],0,",",".").'</td><td align="right">'.number_format($row[Data_length]+$row[Index_length],0,",",".").' Bytes</td><td style="color:#006600;">'.$row[Update_time].'</td></tr>';
|
||||
if(strtotime($row[Update_time])>strtotime($last_update)) $last_update=$row[Update_time];
|
||||
$s1=$s1+$row[Rows];
|
||||
$s2=$s2+$row[Data_length]+$row[Index_length];
|
||||
}
|
||||
echo '<tr class="hellblau"><td colspan="2"><strong>'.$l["info_sum"].'</strong></td><td align="right"><strong>'.number_format($s1,0,",",".").'</strong></td><td align="right"><strong>'.number_format($s2,0,",",".").' Bytes</strong></td><td style="color:#006600;"><strong>'.$last_update.'</strong></td></tr>';
|
||||
echo '</table>';
|
||||
}
|
||||
$edb=$l["info_emptydb1"].' `'.$dbname_a[$dbid].'` '.$l["info_emptydb2"];
|
||||
$kdb=$l["info_emptydb1"].' `'.$dbname_a[$dbid].'` '.$l["info_killdb"];
|
||||
|
||||
echo '<form action="'.$PHP_SELF.'?action=db" method="post"><table><tr>';
|
||||
if($numrows>0) echo '<td><input class="Formbutton2" type="submit" name="empty'.$dbid.'" value="'.$l["clear_database"].'" onclick="if (!confirm(\''.$edb.'\')) return false;"></td>';
|
||||
echo '<td><input class="Formbutton2" type="submit" name="kill'.$dbid.'" value="'.$l["delete_database"].'" onclick="if (!confirm(\''.$kdb.'\')) return false;"></td>';
|
||||
echo '</tr></table>';
|
||||
}
|
||||
include("footer.php");
|
||||
?>
|
||||
Laden …
Tabelle hinzufügen
Einen Link hinzufügen
In neuem Issue referenzieren