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 = "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."
?>