标签:
备份代码如下:
logger.info(dbName + "开始备份!"); String cmd = "\"\" \""+dataBaseBS.getInstallPath() +"bin\\mysqldump\" -h localhost -uroot -p123456 " + dbName + " > \"" + uploadPath + dbName + ".sql\""; // 一定要加 -h,localhost(或是服务器IP地址) Process process = Runtime.getRuntime().exec("cmd /c start /b " + cmd); InputStreamReader isr = new InputStreamReader(process.getErrorStream()); LineNumberReader input = new LineNumberReader(isr); String line; while ((line = input.readLine()) != null) { } logger.info(dbName + "备份成功!");
还原代码如下:
logger.info(dbName + "开始还原!"); String cmd = "\"\" \""+dataBaseBS.getInstallPath() +"bin\\mysql\" -h localhost -uroot -p123456 " + dbName + " < \"" + uploadPath + dbName + ".sql\""; // 一定要加 -h,localhost(或是服务器IP地址) Process process = Runtime.getRuntime().exec("cmd /c start /b " + cmd); InputStreamReader isr = new InputStreamReader(process.getInputStream()); LineNumberReader input = new LineNumberReader(isr); String line; while ((line = input.readLine()) != null) { } logger.info(dbName + "还原成功!");
标签:
原文地址:http://www.cnblogs.com/Mr-kevin/p/5553651.html