简易代码之家

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  157 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks
Java web程序中备份oracle数据库

1.生成备份文件:

public ActionForward createDmp(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            
throws Exception {
        Calendar c 
= Calendar.getInstance();
        SimpleDateFormat sdf 
= new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName 
= "data_oracle" + sdf.format(c.getTime());
        String dmpFolder 
= request.getSession().getServletContext()
                .getRealPath(
"")
                
+ "\\datas\\dmp\\";
        String logFolder 
= request.getSession().getServletContext()
                .getRealPath(
"")
                
+ "\\datas\\log\\";

        String cmd 
= "exp username/password@orcl file='" + dmpFolder + fileName
                
+ ".dmp' log='" + logFolder + fileName + ".log' owner=username";
        Runtime.getRuntime().exec(cmd);
        Thread.sleep(
100 * 1000);
        request.setAttribute(
"msg""备份成功,文件生成会有延迟,请稍等");
        
return mapping.findForward("dmpCreated");
    }

2.查询备份文件:

public ActionForward findDmp(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            
throws Exception {
        String dmpFolder 
= request.getSession().getServletContext()
                .getRealPath(
"")
                
+ "\\datas\\dmp\\";
        File folder 
= new File(dmpFolder);
        File[] files 
= folder.listFiles();
        List
<String[]> fileList = new ArrayList<String[]>();
        
for (int i = 0; i < files.length; i++{
            
if (files[i].getName().indexOf(".dmp"> 0{
                String[] one 
= new String[2];
                one[
0= files[i].getName();
                one[
1= files[i].length() / 1000 + "K";
                fileList.add(one);
            }

        }

        request.setAttribute(
"fileList", fileList);
        
return mapping.findForward("dmpList");
    }

3.删除备份文件:

public ActionForward deleteDmp(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            
throws Exception {
        String dmpFolder 
= request.getSession().getServletContext()
                .getRealPath(
"")
                
+ "\\datas\\dmp\\";
        File folder 
= new File(dmpFolder);
        File[] files 
= folder.listFiles();
        String fileName 
= request.getParameter("dmpName");
        
for (int i = 0; i < files.length; i++{
            
if (files[i].getName().equals(fileName)) {
                files[i].delete();
                request.setAttribute(
"msg""删除成功");
                
break;
            }

        }

        
return mapping.findForward("dmpList");
    }

posted on 2010-06-08 18:27 Jakin.zhou 阅读(1095) 评论(1)  编辑  收藏

Feedback

# re: Java web程序中备份oracle数据库 2015-01-21 20:43 yanwushu
要是写上如何恢复数据库就更好了  回复  更多评论
  


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


网站导航: