RSS

Restore MySql Backup file by using JAVA

28 Sep

First read my early blog post “Take the MySql DB backup in JAVA” and you can download the source from there


public boolean restoreDatabase(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) {
                log.info("Backup restored successfully with " + source);
                return true;
            } else {
                log.info("Could not restore the backup " + source);
            }
        } catch (Exception ex) {
            log.error(ex, ex.getCause());
        }

        return false;

    }

Advertisements
 
2 Comments

Posted by on September 28, 2012 in java, mysql

 

Tags: , ,

2 responses to “Restore MySql Backup file by using JAVA

  1. GoesPoer

    May 8, 2015 at 10:46 am

    Reblogged this on Kidungsuwung.

     
  2. Noorullah

    April 7, 2016 at 9:34 am

    what is this source is this the saved sql file

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: