First read my early blog post "Take the MySql DB backup in JAVA" and you can download the source from there
[sourcecode language="java"]
public boolean restoreDatabase(String dbUserName, String dbPassword, String source) {
String[] executeCmd = new String[]{"mysql", "--user=" + dbUserName, "--password=" + dbPassword, "-e", "source " + source};
Process runtimeProcess;
try {
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
log.info("Backup restored successfully with " + source);
return true;
} else {
log.info("Could not restore the backup " + source);
}
} catch (Exception ex) {
log.error(ex, ex.getCause());
}
return false;
}
[/sourcecode]
No comments:
Post a Comment