栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 数据库 > MySQL

Thinkphp操作PHP内置函数备份Mysql数据库用法

MySQL 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Thinkphp操作PHP内置函数备份Mysql数据库用法



html模板



	
	


		
  • 于 {$vo} 备份删除 恢复备份




  • DbController.class.php

     '.$dir.$filename.'.sql';
    			$cmd = '"D:phpStudyMySQLbinmysqldump" -u'.C("DB_USER").' -p'.C("DB_PWD").' '.C("DB_NAME").' > '.$dir.$filename.'.sql';
    
    			$res = exec($cmd,$output,$status);
    			//$res = passthru($cmd,$status);
    			//$res = system($cmd,$output);
    			//dump($res);die;
    			if($status){
    				$this->error("备份失败");
    			}else{
    				$this->success("备份成功");
    			}
            }
    		$list = glob($dir."*.sql");
    		foreach($list as $k=>$v){
    			$v1 = explode(".",$v);
    			$time = strtotime(str_replace($dir,'',$v1[0]));
    			if(strlen($time) != 10){
    				continue;
    			}
    			$list[$k] = date("Y-m-d H:i:s",$time);
    		}
    		$this->assign("list",$list);
    		$this->display("index/data");
        }
    
    	function del(){
    		$data = I("item");
    		if(!empty($data)){
    			$dir = $_SERVER["DOCUMENT_ROOT"]."/db_backup/";
    			$file = $dir.date("YmdHis",strtotime($data)).".sql";
    
    			if(file_exists($file)){
    				if(unlink($file)){
    					$this->success("删除成功");
    				}else{
    					$this->success("删除失败");
    				}
    			}
    
    		}
    	}
    
    	function recovery(){
    		$dir = "db_backup/";
    		$data = I("item");
    		if(!empty($data)){
    			$file = $dir.date("YmdHis",strtotime($data)).".sql";
    			$cmd = 'mysql.exe -u'.C("DB_USER").' -p'.C("DB_PWD").' '.C("DB_NAME").' < '.$file;
    
    			//$res = exec($cmd,$output,$status);
    			$res = system($cmd,$output);
    
    			//$res = passthru($cmd,$output);
    
    			if($output){
    
    				$this->error("恢复失败");
    			}else{
    
    				$this->success("恢复成功");
    			}
    		}
    	}
    
    }


    转载请注明:文章转载自 www.mshxw.com
    本文地址:https://www.mshxw.com/it/828747.html
    我们一直用心在做
    关于我们 文章归档 网站地图 联系我们

    版权所有 (c)2021-2022 MSHXW.COM

    ICP备案号:晋ICP备2021003244-6号