`
liwen19840617
  • 浏览: 42657 次
  • 性别: Icon_minigender_2
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

java备份mysql数据库(利用apache的commons包)

    博客分类:
  • java
 
阅读更多
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;
    //子进程执行成功相应操作
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics