Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/09/2011, 19:05
iran394
 
Fecha de Ingreso: enero-2011
Ubicación: Cuba
Mensajes: 124
Antigüedad: 13 años, 3 meses
Puntos: 1
Respuesta: Restaurar copia de seguridad con java

Socio acá te mando un código que me funcionó solo tienes que ponerlo en el evento de un botón
//************************************************** ***********************

int resp;
resp=RealizarBackupMySQL.showSaveDialog(this);//JFileChooser de nombre RealizarBackupMySQL
if (resp==JFileChooser.APPROVE_OPTION) {//Si el usuario presiona aceptar; se genera el Backup
try{
Runtime runtime = Runtime.getRuntime();
File backupFile = newFile(String.valueOf(RealizarBackupMySQL.getSele ctedFile().toString())+Diahoy +"-"+Meshoy+"-"+Aniohoy+".sql");
FileWriter fw = new FileWriter(backupFile);
Process child = runtime.exec("C:\\Archivos de programa\\MySQL\\MySQL Server 5.1\\bin\\mysqldump --opt --password=HdMc --user=root --databases bd_ueta_mysql");

InputStreamReader irs = new InputStreamReader(child.getInputStream());
BufferedReader br = new BufferedReader(irs);

String line;
while( (line=br.readLine()) != null ) {
fw.write(line + "\n");
}
fw.close();
irs.close();
br.close();

JOptionPane.showMessageDialog(null, "Archivo generado","Verificar",JOptionPane. INFORMATION_MESSAGE);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Error no se genero el archivo por el siguiente motivo:"+e.getMessage(), "Verificar",JOptionPane.ERROR_MESSAGE);
}
JOptionPane.showMessageDialog(null, "Archivogenerado","Verificar",JOptionPane.INFORMAT ION_MESSAGE);
} else if (resp==JFileChooser.CANCEL_OPTION) {
JOptionPane.showMessageDialog(null,"Ha sido cancelada la generacion del Backup");
}


//************************************************** *************************