Backup per Mail versenden
Für eine Webapplikation welche mir am Herzen lag und viele User benutzten, hatte ich ein tägliches Backup eingerichtet.
Dieses tägliche Backup wollte ich des Weiteren an die Administratoren / Programmierer verteilen, damit diese wiederum ein Backup hatten, falls irgendwas passieren würde.
Zudem wurde es so auch gleich “ausgelagert” vom Server. Da das komprimierte Backup nur rund 8 MB hatte, ging dies problemlos.
Da ich den Mailversand in der Shell mir nicht antun wollte, bin ich auf PHP ausgewichen:
<?php
$from = 'webmaster@youdomain.com';
$to = 'yourmail@youdomain.com';
$DATEI = '/root/backup/meinbackup.tar.gz';
$content_type = 'application/x-tar';
$subject = 'System Backup from '.date("d.m.Y",time());
// Do not change anything from here
$random_hash = md5(date('r', time()));
$headers = "From: ".$from."\r\nReply-To: ".$from;
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($DATEI)));
$message = "--PHP-mixed-".$random_hash."\n".
"Content-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"\n\n".
"--PHP-alt-".$random_hash."\n".
"Content-Type: text/plain; charset=\"iso-8859-1\"\n".
"Content-Transfer-Encoding: 7bit\n\n".
"CONFIDENTIALITY: This e-mail and any attachments are confidential and may be privileged.\n".
"If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.\n\n".
"--PHP-alt-".$random_hash."--\n\n".
"--PHP-mixed-".$random_hash."\n".
"Content-Type: ".$content_type."; name=\"Backup".date("Ymd",time()).".tar.gz\"\n".
"Content-Transfer-Encoding: base64\n".
"Content-Disposition: attachment\n\n".
$attachment."\n".
"--PHP-mixed-".$random_hash."--\n\n";
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Backup wurde gesendet." : "Backup konnte nicht versandt werden!";
?>Dieses File konnte dann in dem Shellscript mit:
/usr/bin/php -q sendbackup.php
verschickt werden.
Einfach und sehr nützlich.
Benutzer, die diesen Beitrag fanden, suchten nach:
- akkeeba backup per mail schicken
- backup per email
- backup per e-mail
Weitere interessante Beiträge:



