//备份代码 java.io.File file = new java.io.File(backupFilePath); if (!file.exists()) { file.mkdir(); } String path = backupFilePath + "fuzhi_pri_" + DateUtil.getToday().replaceAll("-", "") + ".sql"; String cmd = "mysqldump -hlocalhost -p3306 -uroot -pfuzhi001 fuzhi_pri > " + path; log.error(cmd); Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", cmd});
//恢复代码
String cmd = "mysql -hlocalhost -p3306 -uroot -pfuzhi001 fuzhi_pri < " + backupFilePath + file_name; log.error(cmd); Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", cmd});