MySql Backup
Hier ein kleiner Codeschnipsel der eine Mysql Datenbank
Backupt und das Backup als Email zu deiner Adresse schickt
|
Script: |
<?php
$username = '';#user
$passwort =
'';#passort
$db_name =
'';#Name
der Dantenbank
$filename =
date(d.'.'.m.'.'.Y);
$mail =
'';#deine
Email Adresse
$Betreff =
"Backup der Datenbank
$db_name vom $filename";
system('/usr/bin/mysqldump
-u'.$username.'
-p'.$passwort.'
-h localhost '.$db_name.'
| /bin/gzip > '.$filename.'.sql.gz',
$fp);
if ($fp==0)
echo '';
else echo 'Es ist ein
Fehler aufgetreten';
$filename_n =
$filename.'.sql.gz';
$Header =
"From: Backup System
<$mail>";
$Trenner =
md5(uniqid(time()));
$Header .=
"\n";
$Header .=
"MIME-Version:
1.0";
$Header .=
"\n";
$Header .=
"Content-Type:
multipart/mixed; boundary=$Trenner";
$Header .=
"\n\n";
$Header .=
"This is a multi-part
message in MIME format";
$Header .=
"\n";
$Header .=
"--$Trenner";
$Header .=
"\n";
$Header .=
"Content-Type: text/plain";
$Header .=
"\n";
$Header .=
"Content-Transfer-Encoding:
8bit";
$Header .=
"\n\n";
$Header .=
"Backup der Datenbank
$db_name vom $filename";
$Header .=
"\n";
$Header .=
"--$Trenner";
$Header .=
"\n";
$Header .=
"Content-Type:
application/x-gzip; name=$filename_n";
$Header .=
"\n";
$Header .=
"Content-Transfer-Encoding:
base64";
$Header .=
"\n";
$Header .=
"Content-Disposition:
attachment; filename=$filename_n";
$Header .=
"\n\n";
$Dateiinhalt .=
fread(fopen($filename_n,
"r"),
filesize($filename_n));
$Header .=
chunk_split(base64_encode($Dateiinhalt));
$Header .=
"\n";
$Header .=
"--$Trenner--";
mail($mail,
$Betreff,
"",
$Header);
?>
|
|