发布v2.6.6版本
This commit is contained in:
@@ -54,4 +54,55 @@ class beifenClassAction extends runtAction
|
||||
return 'success';
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份数据库
|
||||
* php task.php beifen,create
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
if(PHP_SAPI != 'cli') return 'plase cli run';
|
||||
$alltabls = $this->db->getalltable();
|
||||
ob_end_clean();
|
||||
$path = ''.ROOT_PATH.'/'.DB_BASE.'_'.date('YmdHis').'.sql';
|
||||
$file = fopen($path, 'ab+');
|
||||
|
||||
$nobeifne = array(''.PREFIX.'log',''.PREFIX.'logintoken',''.PREFIX.'kqanay',''.PREFIX.'email_cont',''.PREFIX.'dailyfx',''.PREFIX.'reads',''.PREFIX.'todo',''.PREFIX.'city'); //不备份的表;
|
||||
|
||||
foreach($alltabls as $tabs){
|
||||
$sqla = $this->db->getall('show create table `'.$tabs.'`');
|
||||
$createsql = $sqla[0]['Create Table'];
|
||||
$createsql = str_replace('`'.$tabs.'`', 'IF NOT EXISTS `'.$tabs.'`', $createsql).";\n";
|
||||
if(!in_array($tabs, $nobeifne)){
|
||||
$strstr = "\nDROP TABLE IF EXISTS `$tabs`;\n";
|
||||
$strstr .= $createsql;
|
||||
fwrite($file,$strstr);
|
||||
|
||||
$rows = $this->db->getall('select * from `'.$tabs.'`', function($rs, $cans){
|
||||
$vstr = '';
|
||||
foreach($rs as $k1=>$v1){
|
||||
if(!isempt($v1))$v1 = str_replace("\n",'\n', $v1);
|
||||
$v1 = ($v1===null) ? 'NULL' : "'$v1'";
|
||||
$vstr.=",$v1";
|
||||
}
|
||||
$vstr = substr($vstr,1);
|
||||
$tabs = $cans['tabs'];
|
||||
$strstr = "INSERT INTO `$tabs` VALUES($vstr);\n";
|
||||
fwrite($cans['file'], $strstr);
|
||||
return $vstr;
|
||||
}, array(
|
||||
'file' => $file,
|
||||
'tabs' => $tabs
|
||||
));
|
||||
|
||||
echo ''.$tabs.' success count('.count($rows).')'.PHP_EOL;
|
||||
}else{
|
||||
fwrite($file,$createsql);
|
||||
echo ''.$tabs.' break'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
fclose($file);
|
||||
|
||||
echo 'success'.PHP_EOL;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user