84 lines
No EOL
1.8 KiB
PHP
84 lines
No EOL
1.8 KiB
PHP
<?php
|
|
|
|
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
require('lib/mysql.class.php');
|
|
|
|
|
|
$pass='maxdata-01'; // SQL PASS
|
|
|
|
$GLOBALS['mysql'] = new mysql('176.9.46.195','edv', $pass);
|
|
|
|
|
|
|
|
function generatePassword()
|
|
{
|
|
//Muster eines sicheren Passworts
|
|
//beispielsweise: Ks#64z
|
|
$pwd = "";
|
|
for ($i = 0; $i < 32; $i ++)
|
|
{
|
|
switch (rand(0, 2))
|
|
{
|
|
case 0 : //Großbuchstabe anfügen
|
|
$pwd = $pwd.chr(rand(65, 90));
|
|
break;
|
|
case 1 : //Kleinbuchstabe
|
|
$pwd = $pwd.chr(rand(97, 122));
|
|
break;
|
|
case 2 : //Ziffer
|
|
$pwd = $pwd.rand(0, 9);
|
|
break;
|
|
}
|
|
}
|
|
return $pwd;
|
|
}
|
|
|
|
|
|
// Die Verbindung herstellen
|
|
$connection_id = ftp_connect('2zjexwrfnvc1pdnh.myfritz.net');
|
|
|
|
// Mit Benutzername und Kennwort anmelden
|
|
$login_result = ftp_login($connection_id, 'hbs', 'SX8NPmabdAyqVX');
|
|
ftp_pasv($connection_id, true);
|
|
if($login_result == true) {
|
|
|
|
$tag=date("d.m.Y-H-i", time());
|
|
$hash=generatePassword();
|
|
mkdir(dirname(__FILE__).'/tmp/'.$hash);
|
|
|
|
$TABLESINF = $GLOBALS['mysql']->query("SHOW DATABASES");
|
|
$gzip =0;
|
|
$datei = date("d\.m\.Y\_H",time())."_Uhr_".date("i",time()); // Dateiname aus Datum und Uhrzeit bilden
|
|
$datei .= ".gz";
|
|
$key=0;
|
|
$is='';
|
|
while($inf = $TABLESINF->fetch_assoc()){
|
|
if($inf['Database'] == 'edv') {
|
|
system("/usr/bin/mysqldump -uroot -p$pass -h localhost '".$inf['Database']."' | gzip > ".dirname(__FILE__).'/tmp/'.$hash.'/'.$inf['Database'].'_'.$datei, $fp);
|
|
|
|
|
|
|
|
$is=$is.' '.$inf['Database'];
|
|
$upload0 = ftp_put($connection_id, '/md1/mybackup/frank/server/sql/'.$inf['Database'].'_'.$datei,'tmp/'.$hash.'/'.$inf['Database'].'_'.$datei, FTP_BINARY);
|
|
if (!$upload0) {
|
|
echo $datei." Datei upload war fehlerhaft!</br>";
|
|
} else {
|
|
unlink('tmp/'.$hash.'/'.$inf['Database'].'_'.$datei);
|
|
}
|
|
|
|
}
|
|
$key++;
|
|
|
|
}
|
|
|
|
rmdir('tmp/'.$hash);
|
|
|
|
ftp_quit($connection_id);
|
|
}
|
|
|
|
// Schließen der Verbindung
|
|
|
|
|
|
?>
|