日期:2014-05-20 浏览次数:20770 次
/**备份数据库**/
File workPath=fetchDBInstallPath();//获取数据库的pg_dump工具的目录
if(workPath==null){
return false;
}
String dbBackupPath=fetchDBBackupPath();
StringBuffer sb=new StringBuffer();
sb.append("cmd /c pg_dump -h 127.0.0.1 -p 5432 -U postgres -F c -b -v -f ").append(dbBackupPath+"\\"+fileName+".backup").append(" dbname");
log.info("**********************************************");
log.info("workPath="+workPath);
log.info("command:"+sb.toString());
log.info("**********************************************");
Process process=Runtime.getRuntime().exec(sb.toString(),null,workPath);
log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "Error"); //线程,用于输出外部程序的输出内容,防止阻塞
StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "Output"); //线程,用于输出外部程序的输出内容,防止阻塞
log.info("+++++++++++++++++++++++++++");
errorGobbler.start();
outputGobbler.start();
process.waitFor();
if(process.exitValue()!=0){
return false;
}