Chinaunix首页 | 论坛 | 博客
  • 博客访问: 314321
  • 博文数量: 111
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 707
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-26 11:00
个人简介

小伙向前冲呀,小伙向前冲呀。

文章分类

全部博文(111)

文章存档

2014年(43)

2013年(68)

我的朋友

分类: PHP

2013-12-02 06:32:51

使用PHP备份MySQL和网站发送到邮箱的方法。
代码如下:
  1. #!/usr/local/bin/php.cli
  2. <?php
  3. require_once './lib/swift_required.php';
  4. //MySQL
  5. $mysql_dbname = "db";
  6. $mysql_user = "user";
  7. $mysql_pass = "pass";
  8. $mysql_file = "./xxx.sql";
  9. $mysql_charset = "utf8";
  10. system("mysqldump --default-character-set=$mysql_charset --opt -u$mysql_user -p$mysql_pass $mysql_dbname > $mysql_file");
  11. //Backup WWW File
  12. $www_path = "../www/";
  13. @$final_file = "./xxx_com_".date("Y_m_d").".zip";
  14. system("zip -r -q $final_file $www_path $mysql_file");
  15. //E-Mail
  16. @$mail_title = "Backup for Coder4.com ".date("Y_m_d");
  17. $mail_sender = "xxx_send@vip.qq.com";
  18. $mail_recver = "xxx_recv@vip.qq.com";
  19. $mail_body = "See attachments";
  20. $mail_file = $final_file;
  21. $sendmail_cmd = "/usr/sbin/sendmail -bs";
  22. //Create E-Mail
  23. $message = Swift_Message::newInstance();
  24. $message->setSubject($mail_title);
  25. $message->setFrom(array($mail_sender));
  26. $message->setTo(array($mail_recver));
  27. $message->setBody($mail_body);
  28. $message->attach(Swift_Attachment::fromPath($mail_file));
  29. //echo $message->toString();
  30. //Send E-Mail
  31. $transport = Swift_SendmailTransport::newInstance($sendmail_cmd);
  32. $mailer = Swift_Mailer::newInstance($transport);
  33. $result = $mailer->send($message);
  34. //Delete
  35. unlink($final_file);
  36. unlink($mysql_file);
  37. //End
  38. echo "All backup success."
  39. ?>
阅读(959) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~