Backup Mysql - JSP

0

It's the first time I try to make a backup of a BD Mysql from a JSP

This is my code (In some forum I saw it).

<%@page import="java.sql.*" %>
<%@page import ="java.util.Calendar" %>
<%
try{
    Calendar fecha = Calendar.getInstance();
    String fechaHoy = fecha.get(Calendar.DATE)+"-"+fecha.get(Calendar.MONTH)+"-"+fecha.get(Calendar.YEAR);
    String nombre = "Respaldo_Sistema_"+fechaHoy+".sql";
    int copia_seguridad;

    Process runtimeProcess = Runtime.getRuntime().exec("C:/xampp/mysql/bin/mysqldump.exe --opt  --password='' --user=root --databases seapto2 -r C:/"+nombre);

    copia_seguridad = runtimeProcess.waitFor(); 

    if(copia_seguridad==0){ //Devuelve 0 si todo ha salido bien
%>      <script> 
            function respaldoRealizado() {
                alert("El respaldo ha sido creado con exito.\n\nCompruebe la ubicacion del archivo en el disco local \nC:");
                location.href="inicio.jsp"; 
            } 
            respaldoRealizado(); 
        </script> 
<%        
    } else {
%>      <script> 
            function respaldoNoRealizado() {
                alert("El respaldo no se pudo generar");
                location.href="inicio.jsp"; 
            } 
            respaldoNoRealizado(); 
        </script> 
<%  
    }

} catch(Exception e){
    out.println(e);
    } 
%>

The problem is that it does not generate any errors, but neither does it generate the backup ...

Any ideas ??

    
asked by Andres Felipe Diaz 19.04.2017 в 19:06
source

2 answers

0

Hello to everyone who saw my post;

The mistake was very simple ... beginner:)

In the creation process "routine" had the following:

Process runtimeProcess = Runtime.getRuntime().exec("C:/xampp/mysql/bin/mysqldump.exe --opt  --password='' --user=root --databases seapto2 -r C:/"+nombre);

When trying to access the BD the password should be NULL something like this:

password= ;

I, on the other hand, had:

password='' 

...... After that I had to fix the name of the file, the separators "-" sometimes cause problems, the functional result would be something like this:

String fechaHoy = fecha.get(Calendar.DATE)+"_"+fecha.get(Calendar.MONTH)+"_"+fecha.get(Calendar.YEAR);

Greetings !!

    
answered by 10.05.2017 / 22:55
source
2

Experience the same error.

In the routine creation process (runtimeProcess) I had the following:

Process runtimeProcess = Runtime.getRuntime().exec("C:/xampp/mysql/bin/mysqldump.exe --opt  --password='' --user=root --databases db_taxi -r C:/"+nombre);

The error showed me when trying to access the database, in case the password is NULL, as is the case is shown this way:

password=''

But it should be like this

password= 

And the code would look like this:

Process runtimeProcess = Runtime.getRuntime().exec("C:\xampp\mysql\bin\mysqldump.exe --opt  --password=  --user=root --databases db_taxi -r C:/"+nombre);
    
answered by 06.03.2018 в 17:50