使用PHP备份MySQL和网站发送到邮箱实例代码_php实例
#!/usr/local/bin/php.cli
require_once './lib/swift_required.php';
//MySQL
$mysql_dbname = "db";
$mysql_user = "user";
$mysql_pass = "pass";
$mysql_file = "./xxx.sql";
$mysql_charset = "utf8";
system("mysqldump --default-character-set=$mysql_charset --opt -u$mysql_user -p$mysql_pass $mysql_dbname > $mysql_file");
//Backup WWW File
$www_path = "../www/";
@$final_file = "./xxx_com_".date("Y_m_d").".zip";
system("zip -r -q $final_file $www_path $mysql_file");
//E-Mail
@$mail_title = "Backup for Coder4.com ".date("Y_m_d");
$mail_sender = "xxx_send@vip.qq.com";
$mail_recver = "xxx_recv@vip.qq.com";
$mail_body = "See attachments";
$mail_file = $final_file;
$sendmail_cmd = "/usr/sbin/sendmail -bs";
//Create E-Mail
$message = Swift_Message::newInstance();
$message->setSubject($mail_title);
$message->setFrom(array($mail_sender));
$message->setTo(array($mail_recver));
$message->setBody($mail_body);
$message->attach(Swift_Attachment::fromPath($mail_file));
//echo $message->toString();
//Send E-Mail
$transport = Swift_SendmailTransport::newInstance($sendmail_cmd);
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
//Delete
unlink($final_file);
unlink($mysql_file);
//End
echo "All backup success."
?>
下一篇: 下载百度搜索图片
推荐阅读
-
PHP imagegrabscreen和imagegrabwindow(截取网站缩略图)的实例代码
-
使用PHP+MySql实现微信投票功能实例代码
-
使用PHP备份MySQL和网站发送到邮箱实例代码
-
php同时使用session和cookie来保存用户登录信息的实现代码_php实例
-
使用phpexcel类实现excel导入mysql数据库功能(实例代码)_php实例
-
PHP imagegrabscreen和imagegrabwindow(截取网站缩略图)的实例代码
-
PHP imagegrabscreen和imagegrabwindow(截取网站缩略图)的实例代码
-
PHP imagegrabscreen和imagegrabwindow(截取网站缩略图)的实例代码
-
使用PHP备份MySQL和网站发送到邮箱实例代码_PHP
-
php使用cookie实现记住用户名和密码实现代码_php实例