框架是springboot,方法的参数都在application.properties中配置,然后再调用层获取的
@ApiImplicitParams({ @ApiImplicitParam(name = "mysqlDumpExe",value = "mysqldump.exe的安装路径"),
@ApiImplicitParam(name = "ip",value = "数据库IP地址"),
@ApiImplicitParam(name = "port",value = "数据库端口"),
@ApiImplicitParam(name = "username",value = "数据库用户名"),
@ApiImplicitParam(name = "password",value = "密码"),
@ApiImplicitParam(name = "dbName",value = "数据库名称"),
@ApiImplicitParam(name = "backPath",value = "备份文件地址"),
@ApiImplicitParam(name = "backName",value = "备份文件名称")
})
public static String backUpDb(String mysqlDumpExe,String ip,String port,String username,String password,
String dbName,String backPath,String backName) throws Exception{
String filePath = backPath+backName;
File file = new File(filePath);
if(!file.exists()){
file.createNewFile();
}
StringBuffer sb = new StringBuffer();
sb.append(mysqlDumpExe);
sb.append("mysqldump");
sb.append(" -u"+username);
sb.append(" -p"+password);
sb.append(" -p"+port);
sb.append(" -h"+ip);
sb.append(" "+dbName+" >");
sb.append(filePath);
System.out.println(sb);
Runtime runtime = Runtime.getRuntime();
runtime.exec("cmd /c"+sb.toString());
return filePath;
}
windows下java备份mysql工具类
最新推荐文章于 2022-11-11 09:14:21 发布