Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static String connexedbname = "connexedb";
- static String archivedbname = "archivedb";
- static String username = "root";
- static String password = "password";
- static String destination = "D:/DB_Backup/";
- public static void doBackupAndRestore() {
- System.out.println("fet");
- int processComplete_export;
- int processComplete_import;
- String backupFile = destination + connexedbname + "-" + DateUtilities.getYear() + ".sql";
- File file = new File(destination);
- if (!file.exists()) {
- file.mkdir();
- }
- File[] databases = file.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File arg0, String arg1) {
- return arg1.toLowerCase().endsWith(".sql");
- }
- });
- System.out.println("Restore Data....");
- for (File f : databases) {
- try {
- System.out.println("play");
- String executeCmd = "";
- executeCmd = "C:/xampp/mysql/bin/mysql -u " + username + " -p" + password + " " + archivedbname + " < "
- + f;
- Process runtimeProcess_importing = Runtime.getRuntime().exec(executeCmd);
- processComplete_import = runtimeProcess_importing.waitFor();
- if (processComplete_import == 1) {
- System.out.println("restore Failed");
- } else if (processComplete_import == 0) {
- System.out.println("restore created Successfully.");
- }
- } catch (Exception e) {
- System.out.println(e);
- continue;
- }
- }
- try {
- System.out.println("Back UP Data....");
- Process runtimeProcess_export = Runtime.getRuntime().exec("C:/xampp/mysql/bin/mysqldump -u " + username
- + " -p" + password + " " + connexedbname + " -r " + backupFile);
- processComplete_export = runtimeProcess_export.waitFor();
- if (processComplete_export == 1) {
- System.out.println("Backup Failed");
- } else if (processComplete_export == 0) {
- System.out.println("Backup created Successfully.");
- }
- } catch (Exception e) {
- System.out.println(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement