在javajspservlet应用程序中通过点击按钮备份mysql

js5cn81o  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(307)

我想在我的前端设置一个按钮,点击该按钮后,我想备份我的mysql数据库并下载sql文件。真的有办法完成这个任务。谢谢。

Process p = null;
        try {
            Runtime runtime = Runtime.getRuntime();
            p = runtime.exec("mysqldump -u dinmarkh_root -pushanlac absdfer_bldb > /home/abcd/a.com/back.bcdsql");
            InputStream inputStream = p.getInputStream();
            ServletOutputStream strm = resp.getOutputStream();
            byte[] buffer = new byte[4096];
            int bytesRead = -1;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                strm.write(buffer, 0, bytesRead);
            }
            inputStream.close();
            strm.close();
            int processComplete = p.waitFor();
            if (processComplete == 0) {
                System.out.println("Backup created successfully!");
            } else {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题