backup of specific mysql content data via java

Asked

Viewed 588 times

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 backup, it saves the entire system, including tables that are not needed, I want to backup a certain table, with a certain field.

What happens: I have a system that works with point card, that is, I create a point card per day for each process and, It may have processes with years of time, IE, the point card linked to the process will have thousands of Inserts, and I will make it possible to put this inside the system (update the bd directly from the system) and if I do the whole bd it would take time, but if I save the Drops Tables in one file and the Inserts in another would make it easier. And preferably, I can save the point cards that are linked to a specific process, because then, it further reduces the size of the backup.

From now on, thank you

1 answer

0


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

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 pick up specific fields there I know no way to do 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;
  • So, actually it’s not taking the specific fields, it’s taking the records that have given given, let’s say, every process has several dots linked cards, and let’s say I want all the dots cards that have the id=3 process for example, you know? is a little different from picking up a particular column, but it already sums up quite the processing time of restoring the backup, if you know how to answer this other question, I really appreciate it!

  • Dear in this case I know no other way than through select into outfile with Where clause, when you want to import the data use LOAD DATA INFILE 'FILENAME' INTO TABLE TABLENAME', ref: http://dev.mysql.com/doc/refman/5.7/en/load-data.html, this way you can create your own backup the way you want. I hope it helps.

  • Thanks! I’ll try to do here!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.