backup mysql specific content data via java

0

Hello, I have the following method that backs up my database:

public static void makeBackup() throws IOException{
    String caminho = "C:\Program Files\MySQL\MySQL Workbench 6.3 CE\mysqldump.exe";
    ProcessBuilder pb = new ProcessBuilder(caminho, "--user=root",
            "--password=root", "meuBD", "--result-file="
            + "C:\Users\Usuário\Documents\NetBeansProjects\meuPrograma\" + "Backup.txt");
    pb.start();
}

The problem is: when I back up, it saves the entire system, including tables that are not needed, I want to back up a certain table with a given field.

What happens: I have a system that works with a point card, that is, I create a point card per day for each process and, it may be that it has processes with years of time, ie, the point card linked to the process will have thousands of inserts, and I'm going to make it possible to put this inside the system (do update in bd directly from the system) and if doing the whole bd would be time consuming, but if I save the drops tables to a file and the inserts in other would facilitate. And preferably, I can save the point cards that are linked to a specific process, because there, it further reduces the size of the backup.

Thanks in advance,

    
asked by anonymous 25.05.2016 / 15:40

1 answer

0

To backup a specific table you have to pass the name of the table after the name of the database eg:

public static void makeBackup() throws IOException{
    String caminho = "C:\Program Files\MySQL\MySQL Workbench 6.3 CE\mysqldump.exe";
    ProcessBuilder pb = new ProcessBuilder(caminho, "--user=root",
        "--password=root", "meuBD minhaTabela", "--result-file="
        + "C:\Users\Usuário\Documents\NetBeansProjects\meuPrograma\" + "Backup.txt");
    pb.start();
}

Now if you want to get specific fields then I do not know how to do it through mysqldump, a solution to this would be the SELECT INTO OUTFILE Ex:

  SELECT column_a, column_b, column_a+column_b INTO OUTFILE '~/result.txt'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY '\n'
  FROM table;
    
25.05.2016 / 22:13