Java Restore backup

in #java9 years ago

This code can Restore your mysql backup for system. it helpful for you.

public boolean restoreDB(String dbUserName, String dbPassword, String source) {

 

        String[] executeCmd = new String[]{"mysql", "--user=" + dbUserName, "--password=" + dbPassword, "-e", "source "+source};

 

        Process runtimeProcess;

        try {

 

            runtimeProcess = Runtime.getRuntime().exec(executeCmd);

            int processComplete = runtimeProcess.waitFor();

 

            if (processComplete == 0) {

                System.out.println("Backup restored successfully");

                return true;

            } else {

                System.out.println("Could not restore the backup");

            }

        } catch (Exception ex) {

            ex.printStackTrace();

        }

 

        return false;

    }




//Note: The following method is to restore a complete databas

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.077
BTC 62042.63
ETH 1628.63
USDT 1.00
SBD 0.41