Use PHP to back up MySQL and web site send to mailbox instance code _php instance

Source: Internet
Author: User

Copy Code code as follows:

#!/usr/local/bin/php.cli
<?php
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 = "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."
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.