检查备份已创建

Posted

技术标签:

【中文标题】检查备份已创建【英文标题】:Check Backup was created 【发布时间】:2011-09-16 11:56:13 【问题描述】:

我正在尝试学习 JSP/Servlets...我设法编写了一个备份整个数据库的函数...

package com.functions;

import java.io.*;
import java.io.IOException;
//import java.sql.Connection;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import com.functions.utility.DBConnector;

public class addMarks3 extends HttpServlet 

    private static final long serialVersionUID = 8097085789553030042L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException        

        System.out.println("--------------------");
        System.out.println(" On Backup.java ");
        System.out.println("--------------------");

            fetchDataFromDB(request,response);
    

    private void fetchDataFromDB(HttpServletRequest request,HttpServletResponse response)


        try 
            Runtime runtime = Runtime.getRuntime();
            File backupFile = new File("C:/Users/Rohan/Desktop/LMS/backup.sql");
            FileWriter fw = new FileWriter(backupFile);
            Process child = runtime.exec("C:/Program Files (x86)/mysql/MySQL Server 5.5/bin/mysqldump --user=root --password=root --lock-all-tables --opt dummy");
            InputStreamReader irs = new InputStreamReader(child.getInputStream());
            BufferedReader br = new BufferedReader(irs);

            String line;
            while( (line=br.readLine()) != null ) 
                fw.write(line + "\n");
            
            fw.close();
            irs.close();
            br.close();
         catch (IOException ex) 
            ex.printStackTrace();
        

    

我仍然不知道如何验证备份是否成功..?? 就像我如何检查备份是否成功一样。

PS:每次我运行该文件时都会填充它....

【问题讨论】:

【参考方案1】:

像这样尝试。检查文件大小。

 File backupFile = new File("C:/Users/Rohan/Desktop/LMS/backup.sql");
 int len1=backupFile.length();
 FileWriter fw = new FileWriter(backupFile);

 Process child = runtime.exec("C:/Program Files (x86)/MySQL/MySQL Server 5.5/bin/mysqldump --user=root --password=root --lock-all-tables --opt dummy");
        InputStreamReader irs = new InputStreamReader(child.getInputStream());
        BufferedReader br = new BufferedReader(irs);
        String line;
        while( (line=br.readLine()) != null ) 
            fw.write(line + "\n");
        
        fw.close();
        irs.close();
        br.close(); 

       int len2=backupFile.length();

       int compare=len2-len1;

          if(compare>0)
          
            System.out.println("-- Backup done---");
          

【讨论】:

【参考方案2】:

那么,如果文件每次都被填充,那不就意味着备份成功了吗?

您是否考虑过将流程流传输到响应流?

【讨论】:

以上是关于检查备份已创建的主要内容,如果未能解决你的问题,请参考以下文章

rsync 全网备份

是否需要检查通知通道是否已创建?

如何检查对象是不是已在 C++ 中初始化/创建?

php 检查您的模型是否已创建或找到

RMAN详细教程:备份检查维护恢复

MS SqlServer 通过数据库日志文件找回已删除的记录