Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?
  2. $datestamp = date("Y-m-d"); // Current date to append to filename of backup file in format of YYYY-MM-DD
  3.  
  4. /* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */
  5. $dbuser = ""; // Database username
  6. $dbpwd = ""; // Database password
  7. $dbname = ""; // Database name. Use --all-databases if you have more than one
  8. $filename= "backup-$datestamp.sql.gz"; // The name (and optionally path) of the dump file
  9. $to = "you@remotesite.com"; // Email address to send dump file to
  10. $from = "you@yourhost.com"; // Email address message will show as coming from.
  11. $subject = "MySQL backup file"; // Subject of email
  12.  
  13. $command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
  14. $result = passthru($command);
  15.  
  16. $attachmentname = array_pop(explode("/", $filename)); // If a path was included, strip it out for the attachment name
  17.  
  18. $message = "Compressed database backup file $attachmentname attached.";
  19. $mime_boundary = "<<<:" . md5(time());
  20. $data = chunk_split(base64_encode(implode("", file($filename))));
  21.  
  22. $headers = "From: $from\r\n";
  23. $headers .= "MIME-Version: 1.0\r\n";
  24. $headers .= "Content-type: multipart/mixed;\r\n";
  25. $headers .= " boundary=\"".$mime_boundary."\"\r\n";
  26.  
  27. $content = "This is a multi-part message in MIME format.\r\n\r\n";
  28. $content.= "--".$mime_boundary."\r\n";
  29. $content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
  30. $content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  31. $content.= $message."\r\n";
  32. $content.= "--".$mime_boundary."\r\n";
  33. $content.= "Content-Disposition: attachment;\r\n";
  34. $content.= "Content-Type: Application/Octet-Stream; name=\"$attachmentname\"\r\n";
  35. $content.= "Content-Transfer-Encoding: base64\r\n\r\n";
  36. $content.= $data."\r\n";
  37. $content.= "--" . $mime_boundary . "\r\n";
  38.  
  39. mail($to, $subject, $content, $headers);
  40.  
  41. unlink($filename); //delete the backup file from the server
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement