Dict.CN 在线词典, 英语学习, 在线翻译

都市淘沙者

荔枝FM Everyone can be host

统计

留言簿(23)

积分与排名

优秀学习网站

友情连接

阅读排行榜

评论排行榜

mysql数据库备份与恢复程序

mysql数据库备份与恢复程序  
<%@ page contentType="text/html;charset=gb2312"%> 
<%@ page import="java.util.*,com.fxm.common.*,com.ncucec.*,com.ncucec.dbo.*,java.sql.*,org.hibernate.*"%>

<body>
<%
int j=0;
String action,postid,folder;

action = request.getParameter("action");
postid = request.getParameter("postid");
if ((action==null) || ("".equals(action))) action="main";
if ((null==postid) || ("".equals(postid))) postid="0";

String path,realPath,sql,file,err;
boolean ret=false;


if ("backup".equals(action)){
    path = CnUtils.toChinese(request.getParameter("path"));
    if (CnUtils.isEmpty(path)) path =""; else path=DirList.getRealDir(path);
    //得到查询的绝对路径
    realPath = getServletContext().getRealPath(path);
    
    try{
        //得到路径
        ret = DirList.MakeDir(realPath);
        path = realPath+"\\"+DateUtil.formatDate(new java.util.Date(),"yyMMdd");
        ret = DirList.MakeDir(path);
        path = CnUtils.Replace(path,"\\","/");

        Session ss = HibernateUtil.currentSession();
        Transaction tx = ss.beginTransaction();
        Connection conn= ss.connection();
        Statement st = conn.createStatement();

        file = path+"/news.txt";
        sql = "select * from tbl_news_b into outfile '"+ file +"'";
        st.execute(sql);
        
        file = path+"/column.txt";
        sql = "select * from tbl_column_b into outfile '"+ file +"'";
        st.execute(sql);

        file = path+"/invinfo.txt";
        sql = "select * from tbl_invinfo_r into outfile '"+ file +"'";
        st.execute(sql);

        file = path+"/vote.txt";
        sql = "select * from tbl_vote_r into outfile '"+ file +"'";
        st.execute(sql);

        file = path+"/placard.txt";
        sql = "select * from tbl_placard_b into outfile '"+ file +"'";
        st.execute(sql);

        file = path+"/group.txt";
        sql = "select * from tbl_group_r into outfile '"+ file +"'";
        st.execute(sql);

        file = path+"/user.txt";
        sql = "select * from tbl_user_b into outfile '"+ file +"'";
        st.execute(sql);


        ret = true;
        conn.commit();
    }catch(Exception e){
        out.println(e);
        ret = false;
    }
    if (ret==false)
        out.println("<br><br><p align=center>数据不能正确备份,请稍后再试,或与管理员联系。<a href=# onclick='history.go(-1)'>返回</a></p>");
    else{
        out.println("<br><br><p align=center>数据备份成功。<a href=# onclick='history.go(-1)'>返回</a></p>");
        action="main";
    }
    out.close();
}
if ("restore".equals(action)){
    path = CnUtils.toChinese(request.getParameter("path"));
    if (CnUtils.isEmpty(path)) path =""; else path=DirList.getRealDir(path);
    //得到查询的绝对路径
    realPath = getServletContext().getRealPath(path);
    
    try{
        //得到路径
        ret = DirList.MakeDir(realPath);
        path = realPath+"\\"+DateUtil.formatDate(new java.util.Date(),"yyMMdd");
        ret = DirList.MakeDir(path);
        path = CnUtils.Replace(path,"\\","/");

        Session ss = HibernateUtil.currentSession();
        Transaction tx = ss.beginTransaction();
        Connection conn= ss.connection();
        Statement st = conn.createStatement();

        file = path+"/column.txt";
        sql = "load data infile '"+file+"' replace into table tbl_column_b";
        st.execute(sql);
        
        file = path+"/news.txt";
        sql = "load data infile '"+file+"' replace into table tbl_news_b";
        st.execute(sql);
        
        file = path+"/vote.txt";
        sql = "load data infile '"+file+"' replace into table tbl_vote_r";
        st.execute(sql);
        
        file = path+"/placard.txt";
        sql = "load data infile '"+file+"' replace into table tbl_placard_b";
        st.execute(sql);
        
        file = path+"/invinfo.txt";
        sql = "load data infile '"+file+"' replace into table tbl_invinfo_r";
        st.execute(sql);

        file = path+"/template.txt";
        sql = "load data infile '"+file+"' replace into table tbl_template_r";
        st.execute(sql);

        file = path+"/group.txt";
        sql = "load data infile '"+file+"' replace into table tbl_group_r";
        st.execute(sql);

        file = path+"/user.txt";
        sql = "load data infile '"+file+"' replace into table tbl_user_r";
        st.execute(sql);

        ret = true;
        conn.commit();
    }catch(Exception e){
        out.println(e);
        ret = false;
    }
    if (ret==false)
        out.println("<br><br><p align=center>数据不能正确恢复,请稍后再试,或与管理员联系。<a href=# onclick='history.go(-1)'>返回</a></p>");
    else{
        out.println("<br><br><p align=center>数据恢复成功。<a href=# onclick='history.go(-1)'>返回</a></p>");
        action="main";
    }
    out.close();
}
if ("main".equals(action)){
%>
<script language="javascript">
    // 表单提交(当远程上传完成后,触发此函数)
    function doSubmit(type){
        document.a1.action.value = type;
        document.a1.submit();
    }
</script>

<table width="550" cellspacing=1 cellpadding=1 align=center style="border: 1 solid #808080" border="0"> 
  <tr> 
    <th height=25>   <B>备份系统数据库</B></th> 
  </tr> 
  <form method="post" action="?" id=a1 name=a1> 
  <input type=text name="action" value="backup">
    <tr> 
      <td bgcolor="ffffff" height="22"> 备份目录: 
        <input type=text size=20 name="path" value="backup"></td> 
    </tr> 
    <tr> 
      <td bgcolor="efefef" height="25">  
        <input type=button value=" 备 份 数 据 " onclick="doSubmit('backup')">   <input type=button value=" 恢 复 数 据 " onclick="doSubmit('restore')"></td> 
    </tr> 
  </form> 
</table> 
<%
}
%>

posted on 2006-04-25 17:00 都市淘沙者 阅读(558) 评论(0)  编辑  收藏 所属分类: Oracle/Mysql/Postgres/


只有注册用户登录后才能发表评论。


网站导航: