快捷搜索:   nginx

备份MYSQL数据到邮箱

备份MYSQL数据到邮箱 作者: tongj   发布日期: 2008-1-11    查看数: 88   出自: http://www.phpx.com 最近写了个自动备份MYSQL数据到邮箱的程序,程序倒是没问题,可是邮箱却经常拒收我的邮件
我的数据导出后再压缩估计有1G,按10M一份分开有100份左右.开始是用YAHOO的,但是收到几封邮件后就全部拒收了,然后换网易的YEAH,但是每次都有十几封被拒收,说是邮件不符合他们的政策.
我每次备份都是在凌晨,而且还试过发一封SLEEP一下,也不行,大家有没有好一点的办法?
CODE: <?php
function send_mail($subject,$emailbody,$filedir,$fname)
{
$to="tongjun741@yahoo.cn";
$fp = fopen($filedir, "r");
$attachment = fread($fp, filesize($filedir));
$attachment = base64_encode($attachment);
$attachment = chunk_split($attachment);
$boundary = uniqid( "");
$headers = "Content-Type: multipart/mixed;
boundary=\"$boundary\"";
$emailbody = "--$boundary
Content-Type: text/plain; charset=gbk
Content-Transfer-Encoding: 7bit

$emailbody

--$boundary
Content-Type: text/html; name=\"$fname\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=\"$fname\"
$attachment

--$boundary
";


mail($to, $subject, $emailbody, $headers);
}

exec("rm -rf alldb.sql");
exec("rm -rf x*");
exec("mysqldump --all-databases --opt -p123456>/root/alldb.sql");
exec("tar c alldb.sql|split -b 10m");

$u_exec="";
exec("ls |grep \"^x\"",$u_exec);

$emailbody="这是mysql date的备份文件,包含以下几个文件:<br>\r\n";
$f_num=0;
$i=0;
$u_num=count($u_exec);
while ($i<$u_num)
{
if (substr($u_exec[$i],0,1)=="x")
{
$emailbody.=$u_exec[$i]."<br>\r\n";
$f_num++;
}
$i++;
}
$emailbody.="共".$f_num."个文件<br>\r\n";

$i=0;
$j=1;
$u_num=count($u_exec);
while ($i<$u_num)
{
if (substr($u_exec[$i],0,1)=="x")
{
send_mail("mysql date的备份文件(".$j."/".$f_num.")".date("Y-m-d H:i:s"),$emailbody,$u_exec[$i],$u_exec[$i]);
}
$i++;
$j++;
}
?&gt;

顶(1)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论