function Ebak_BakExeT($t, $s, $p, $mypath, $alltotal, $thenof, $fnum, $auf = '', $aufval = 0, $stime = 0) { global $empire, $bakpath, $limittype, $fun_r; if (empty($mypath)) { printerror('ErrorUrl', 'history.go(-1)'); } $path = $bakpath . '/' . $mypath; @(include $path . '/config.php'); if (empty($b_table)) { printerror('ErrorUrl', 'history.go(-1)'); } $waitbaktime = (int) $_GET['waitbaktime']; if (empty($stime)) { $stime = time(); } $header = "<?php\nrequire(\"../../inc/header.php\");\n"; $footer = "\nrequire(\"../../inc/footer.php\");\n?>"; $btb = explode(',', $b_table); $count = count($btb); $t = (int) $t; $s = (int) $s; $p = (int) $p; if ($t >= $count) { echo "<script>alert('" . $fun_r['BakSuccess'] . "\\n\\n" . $fun_r['TotalUseTime'] . ToChangeUseTime($stime) . "');self.location.href='ChangeDb.php';</script>"; exit; } $dumpsql = Ebak_ReturnVer(); $u = $empire->query("use `{$b_dbname}`"); if ($b_dbchar == 'auto') { if (empty($s)) { $status_r = Ebak_GetTotal($b_dbname, $btb[$t]); $collation = Ebak_GetSetChar($status_r['Collation']); DoSetDbChar($collation); $num = $limittype ? -1 : $status_r['Rows']; } else { $collation = $_GET['collation']; DoSetDbChar($collation); $num = (int) $alltotal; } $dumpsql .= Ebak_ReturnSetNames($collation); } else { DoSetDbChar($b_dbchar); if (empty($s)) { if ($limittype) { $num = -1; } else { $status_r = Ebak_GetTotal($b_dbname, $btb[$t]); $num = $status_r['Rows']; } } else { $num = (int) $alltotal; } } if ($b_stru && empty($s)) { $dumpsql .= Ebak_Returnstru($btb[$t], $b_strufour); } if (empty($fnum)) { $return_fr = Ebak_ReturnTbfield($b_dbname, $btb[$t], $b_autofield); $fieldnum = $return_fr['num']; $noautof = $return_fr['autof']; $auf = $return_fr['auf']; } else { $fieldnum = $fnum; $noautof = $thenof; } $aufval = (int) $aufval; if ($b_autoauf == 1 && $auf) { $sql = $empire->query('select * from `' . $btb[$t] . '` where ' . $auf . '>' . $aufval . ' order by ' . $auf . " limit {$b_bakline}"); } else { $sql = $empire->query('select * from `' . $btb[$t] . "` limit {$s},{$b_bakline}"); } $inf = ''; if ($b_beover == 1) { $inf = '(' . Ebak_ReturnInTbfield($b_dbname, $btb[$t]) . ')'; } $hexf = ''; if ($b_bakdatatype == 1) { $hexf = Ebak_ReturnInStrTbfield($b_dbname, $btb[$t]); } $b = 0; while ($r = $empire->fetch($sql)) { if ($auf) { $lastaufval = $r[$auf]; } $b = 1; $s++; $dumpsql .= "E_D(\"" . $b_insertf . ' into `' . $btb[$t] . '`' . $inf . ' values('; $first = 1; for ($i = 0; $i < $fieldnum; $i++) { if (empty($first)) { $dumpsql .= ','; } else { $first = 0; } $myi = $i + 1; if (!isset($r[$i]) || strstr($noautof, ',' . $myi . ',')) { $dumpsql .= 'NULL'; } else { $dumpsql .= Ebak_ReSqlFtext($r[$i], $b_bakdatatype, $myi, $hexf); } } $dumpsql .= ");\");\r\n"; } if (empty($b)) { if (empty($p)) { $p++; $sfile = $path . '/' . $btb[$t] . '_' . $p . '.php'; $dumpsql = $header . $dumpsql . $footer; WriteFiletext_n($sfile, $dumpsql); } Ebak_RepFilenum($p, $btb[$t], $path); $t++; $empire->free($sql); echo "<meta http-equiv=\"refresh\" content=\"" . $waitbaktime . ";url=phomebak.php?phome=BakExeT&s=0&p=0&t={$t}&mypath={$mypath}&stime={$stime}&waitbaktime={$waitbaktime}\">" . $fun_r['OneTableBakSuccOne'] . $btb[$t - 1] . $fun_r['OneTableBakSuccTwo']; exit; } $p++; $sfile = $path . '/' . $btb[$t] . '_' . $p . '.php'; $dumpsql = $header . $dumpsql . $footer; WriteFiletext_n($sfile, $dumpsql); $empire->free($sql); echo "<meta http-equiv=\"refresh\" content=\"" . $waitbaktime . ";url=phomebak.php?phome=BakExeT&s={$s}&p={$p}&t={$t}&mypath={$mypath}&alltotal={$num}&thenof={$noautof}&fieldnum={$fieldnum}&auf={$auf}&aufval={$lastaufval}&stime={$stime}&waitbaktime={$waitbaktime}&collation={$collation}\">" . $fun_r['BakOneDataSuccess'] . Ebak_EchoBakSt($btb[$t], $count, $t, $num, $s); exit; }
function Ebak_BakExeT($t,$s,$p,$mypath,$alltotal,$thenof,$fnum,$auf='',$aufval=0,$stime=0){ global $empire,$bakpath,$limittype,$fun_r; if(empty($mypath)) { printerror("ErrorUrl","history.go(-1)"); } $path=$bakpath."/".$mypath; @include($path."/config.php"); if(empty($b_table)) { printerror("ErrorUrl","history.go(-1)"); } $waitbaktime=(int)$_GET['waitbaktime']; if(empty($stime)) { $stime=time(); } $header="<?php require(\"../../inc/header.php\"); "; $footer=" require(\"../../inc/footer.php\"); ?>"; $btb=explode(",",$b_table); $count=count($btb); $t=(int)$t; $s=(int)$s; $p=(int)$p; //备份完毕 if($t>=$count) { echo"<script>alert('".$fun_r['BakSuccess']."\\n\\n".$fun_r['TotalUseTime'].ToChangeUseTime($stime)."');self.location.href='ChangeDb.php';</script>"; exit(); } $dumpsql=Ebak_ReturnVer(); //选择数据库 $u=$empire->query("use `$b_dbname`"); //编码 if($b_dbchar=='auto') { if(empty($s)) { $status_r=Ebak_GetTotal($b_dbname,$btb[$t]); $collation=Ebak_GetSetChar($status_r['Collation']); DoSetDbChar($collation); //总记录数 $num=$limittype?-1:$status_r['Rows']; } else { $collation=$_GET['collation']; DoSetDbChar($collation); $num=(int)$alltotal; } $dumpsql.=Ebak_ReturnSetNames($collation); } else { DoSetDbChar($b_dbchar); if(empty($s)) { //总记录数 if($limittype) { $num=-1; } else { $status_r=Ebak_GetTotal($b_dbname,$btb[$t]); $num=$status_r['Rows']; } } else { $num=(int)$alltotal; } } //备份数据库结构 if($b_stru&&empty($s)) { $dumpsql.=Ebak_Returnstru($btb[$t],$b_strufour); } //取得字段数 if(empty($fnum)) { $return_fr=Ebak_ReturnTbfield($b_dbname,$btb[$t],$b_autofield); $fieldnum=$return_fr['num']; $noautof=$return_fr['autof']; $auf=$return_fr['auf']; } else { $fieldnum=$fnum; $noautof=$thenof; } //自动识别自增项 $aufval=(int)$aufval; if($b_autoauf==1&&$auf) { $sql=$empire->query("select * from `".$btb[$t]."` where ".$auf.">".$aufval." order by ".$auf." limit $b_bakline"); } else { $sql=$empire->query("select * from `".$btb[$t]."` limit $s,$b_bakline"); } //完整插入 $inf=''; if($b_beover==1) { $inf='('.Ebak_ReturnInTbfield($b_dbname,$btb[$t]).')'; } //十六进制 $hexf=''; if($b_bakdatatype==1) { $hexf=Ebak_ReturnInStrTbfield($b_dbname,$btb[$t]); } $b=0; while($r=$empire->fetch($sql)) { if($auf) { $lastaufval=$r[$auf]; } $b=1; $s++; $dumpsql.="E_D(\"".$b_insertf." into `".$btb[$t]."`".$inf." values("; $first=1; for($i=0;$i<$fieldnum;$i++) { //首字段 if(empty($first)) { $dumpsql.=','; } else { $first=0; } $myi=$i+1; if(!isset($r[$i])||strstr($noautof,','.$myi.',')) { $dumpsql.='NULL'; } else { $dumpsql.=Ebak_ReSqlFtext($r[$i],$b_bakdatatype,$myi,$hexf); } } $dumpsql.=");\");\r\n"; } if(empty($b)) { //最后一个备份 if(empty($p)) { $p++; $sfile=$path."/".$btb[$t]."_".$p.".php"; $dumpsql=$header.$dumpsql.$footer; WriteFiletext_n($sfile,$dumpsql); } Ebak_RepFilenum($p,$btb[$t],$path); $t++; $empire->free($sql); //进入下一个表 //echo $fun_r['OneTableBakSuccOne'].$btb[$t].$fun_r['OneTableBakSuccTwo']."<script>self.location.href='phomebak.php?phome=BakExeT&s=0&p=0&t=$t&mypath=$mypath&stime=$stime';</script>"; echo"<meta http-equiv=\"refresh\" content=\"".$waitbaktime.";url=phomebak.php?phome=BakExeT&s=0&p=0&t=$t&mypath=$mypath&stime=$stime&waitbaktime=$waitbaktime\">".$fun_r['OneTableBakSuccOne'].$btb[$t-1].$fun_r['OneTableBakSuccTwo']; exit(); } //进入下一组 $p++; $sfile=$path."/".$btb[$t]."_".$p.".php"; $dumpsql=$header.$dumpsql.$footer; WriteFiletext_n($sfile,$dumpsql); $empire->free($sql); //echo $fun_r['BakOneDataSuccess'].Ebak_EchoBakSt($btb[$t],$count,$t,$num,$s)."<script>self.location.href='phomebak.php?phome=BakExeT&s=$s&p=$p&t=$t&mypath=$mypath&alltotal=$num&thenof=$noautof&fieldnum=$fieldnum&auf=$auf&aufval=$lastaufval&stime=$stime';</script>"; echo"<meta http-equiv=\"refresh\" content=\"".$waitbaktime.";url=phomebak.php?phome=BakExeT&s=$s&p=$p&t=$t&mypath=$mypath&alltotal=$num&thenof=$noautof&fieldnum=$fieldnum&auf=$auf&aufval=$lastaufval&stime=$stime&waitbaktime=$waitbaktime&collation=$collation\">".$fun_r['BakOneDataSuccess'].Ebak_EchoBakSt($btb[$t],$count,$t,$num,$s); exit(); }
public function backup() { $t = $_GET['t']; $s = $_GET['e']; $p = $_GET['p']; $savepath = $_REQUEST['savepath'] ? $_REQUEST['savepath'] : date("YmdHis", time()); $alltotal = $_GET['alltotal']; $thenof = $_GET['thenof']; $fnum = $_GET['fnum']; $stime = $_GET['stime']; $bakpath = C("DB_BAKPATH"); $b_table = $_SESSION['b_table']; //要备份的表checkbox$_POST['checkbox']; if ($_REQUEST['baktable']) { $_SESSION['b_table'] = $_REQUEST['baktable']; //备份信息 $b_table = $_REQUEST['baktable']; //要备份的表checkbox$_POST['checkbox']; } if ($_REQUEST['info']) { $_SESSION['bak_info'] = $_REQUEST['info']; } //备份信息 Mheader("utf-8"); if (empty($savepath)) { $this->error("必须指定备份数据库保存目录"); } $path = $bakpath . "/" . $savepath; if (empty($b_table)) { $this->error("要备份的数据表不能为空"); } $waitbaktime = $this->waitbaktime; if (empty($stime)) { $stime = time(); } $btb = explode(",", $b_table); $count = count($btb); $t = (int) $t; $s = (int) $s; $p = (int) $p; //备份完毕 $btb[$t] = str_replace(";", "", $btb[$t]); if ($t >= $count) { MakeFile($_SESSION['bak_info'], $path . "/info.txt"); //保存备注信息 unset($_SESSION['b_table'], $_SESSION['bak_info']); echo "<script>alert('备份完成\\n\\n共用时" . UseTime($stime) . "');self.location.href='" . __URL__ . "';</script>"; exit; } $cpright = Cpright(); //版权信息 //编码 $b_dbchar = "utf-8"; //默认使用utf-8 if ($b_dbchar == 'auto') { if (empty($s)) { $status_r = Ebak_GetTotal($b_dbname, $btb[$t]); $collation = Ebak_GetSetChar($status_r['Collation']); DoSetDbChar($collation); //总记录数 $num = $limittype ? -1 : $status_r['Rows']; } else { $collation = $_GET['collation']; DoSetDbChar($collation); $num = (int) $alltotal; } $dumpsql .= Ebak_ReturnSetNames($collation); } else { if (empty($s)) { //总记录数 if ($limittype) { $num = -1; } else { $status_r = M()->query("SHOW TABLE STATUS LIKE '" . $btb[$t] . "';"); //当前表的总记录数 $num = $status_r[0]['Rows']; } } else { $num = (int) $alltotal; } } //备份数据库结构 if (empty($s)) { $dumpsql .= DB_t_stru($btb[$t]); } //取得字段数 if (empty($fnum)) { $return_fr = GetTbField($btb[$t]); $fieldnum = $return_fr['num']; //字段数 $noautof = $return_fr['autof']; } else { $fieldnum = $fnum; $noautof = $thenof; } //完整插入 $inf = ''; if ($b_beover == 1) { $inf = '(' . GetInsertSql($btb[$t]) . ')'; //插入语句的字段 } $b = 0; $sql = mysql_query("select * from `" . $btb[$t] . "` limit {$s},{$num}"); while ($r = mysql_fetch_array($sql)) { $b = 1; $s++; $dumpsql .= "DB_I(\"" . $this->b_insertf . " into `" . $btb[$t] . "`" . $inf . " values("; $first = 1; for ($i = 0; $i < $fieldnum; $i++) { //首字段 if (empty($first)) { $dumpsql .= ','; } else { $first = 0; } $myi = $i + 1; if (!isset($r[$i]) || strstr($noautof, ',' . $myi . ',')) { $dumpsql .= 'NULL'; } else { $dumpsql .= GetFieldStr($r[$i]); } } $dumpsql .= ");\");\r\n"; //是否超过限制 if (strlen($dumpsql) >= $this->b_filesize * 1024) { $p++; $sfile = $path . "/" . $btb[$t] . "_" . $p . ".php"; $dumpsql = "<?php\r\n" . $cpright . $dumpsql . "\r\n?>"; MakeFile($dumpsql, $sfile); //M()->free($sql);释放内存 echo "<meta http-equiv=\"refresh\" content=\"" . $this->waitbaktime . ";url=" . __URL__ . "/backup?e={$s}&p={$p}&t={$t}&savepath={$savepath}&alltotal={$num}&thenof={$noautof}&fieldnum={$fieldnum}&stime={$stime}&waitbaktime={$this->waitbaktime}&collation={$collation}\">成功备份{$btb[$t]}的第{$p}个分卷" . EchoBakSt($btb[$t], $count, $t, $num, $s); exit; } } //最后一个备份 if (empty($p) || $b == 1) { $p++; $sfile = $path . "/" . $btb[$t] . "_" . $p . ".php"; $dumpsql = "<?php\r\n" . $cpright . $dumpsql . "\r\n?>"; MakeFile($dumpsql, $sfile); } //ReFlashConfig($p,$btb[$t],$path); $t++; //M()->free($sql);释放内存 //进入下一个表 echo "<meta http-equiv=\"refresh\" content=\"" . $this->waitbaktime . ";url=" . __URL__ . "/backup?e=0&p=0&t={$t}&savepath={$savepath}&stime={$stime}&waitbaktime={$this->waitbaktime}\">成功备份" . $btb[$t - 1] . "表"; exit; }