检查备份已创建
我正在尝试学习 JSP/Servlet...我设法编写了一个备份整个数据库的函数...
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:每次我运行它时,该文件都会被填充......
I'm trying to learn JSP/Servlets... I managed to write a function that takes a backup of the whole database...
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();
}
}
}
I still cant figure out how to verify if the backup was successful..??
As in how do i check if the backup was succesfull or not.
PS: The file does get populated everytime i run it....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样。检查文件大小。
Try like this.Check for the file sizes.
那么,如果每次都填充该文件,是不是就意味着备份成功了?
您是否考虑过将进程流流式传输到响应流?
Well, if the file gets populated everytime, doesn't that mean that the backup was successful?
Have you considered either streaming the process stream to the response stream?