|
发表于 2017-6-12 14:06:47
|
显示全部楼层
PHP复制代码
case 'add':
//生成数据库备份
$this->load->helper('string');
$this->load->dbutil();
$prefs = array(
'ignore' => array($this->db->dbprefix('ci_sessions')),
'format' => 'txt'
);
$backup = $this->dbutil->backup($prefs);
$this->load->helper('file');
write_file ($bak_dir.$this->db->database.'_'.date('Ymd').'_'.random_string ('alnum', 8).'.sql', $backup);
$data['mes']="备份成功!";
$data['backurl']= base_url ('/set/backup');
$this->load->view('templates/note',$data);
break;
case 'recover': //恢复指定数据库
$this->load->helper('file');
$this->load->helper('string');
$file = $bak_dir.$id; //.sql文件实际地址
//数据库信息
$host = $this->db->hostname;
$user = $this->db->username;
$pwd = $this->db->password;
$db = $this->db->database;
$string = read_file ($file);
$mysqli = new mysqli ($host,$user,$pwd,$db);
$mysqli->set_charset("utf8");
$result = $mysqli->multi_query($string);
$mysqli->close();
if($result){
$data['mes']="数据库恢复成功!";
} else{
$data['mes']="数据库恢复失败!";
}
$data['backurl']= base_url ('/set/backup');
$this->load->view('templates/note',$data);
break;
复制代码 |
|