CommandLine commandLine = CommandLine.parse("\"" + mysqlDir + "mysqldump\"");
commandLine.addArgument("--host=192.168.42.161");
commandLine.addArgument("--port=" + port);
commandLine.addArgument("--user=" + username);
commandLine.addArgument("--password=" + password);
commandLine.addArguments("--databases " + database);
commandLine.addArgument("--result-file=" + directory + "/" + filename);
commandLine.addArgument("--default-character-set=utf8");
//线程看护狗,kill run-away thread
ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
//执行者
Executor executor = new DefaultExecutor();
//正常执行后的退出码
//executor.setExitValue(1);
//安装看护狗
//executor.setWatchdog(watchdog);
//执行命令,收集结果(供程序使用)
int exitvalue = executor.execute(commandLine);
if (executor.isFailure(exitvalue))
{
flag = false;
}
else
{
flag = true;
//子进程执行成功相应操作
}
java备份mysql数据库(利用apache的commons包)
最新推荐文章于 2024-08-20 10:54:35 发布