Post Reply  Post Thread 
MySQL 5.0 backup from java
Author Message
sanjay_sharma77
Junior Member
**


Posts: 1
Group: Registered
Joined: Nov 2007
Status: Offline
Reputation: 0
Thank 0
0 was given thank in 0 posts
Post: #1
MySQL 5.0 backup from java

I'm using mySQL 5.0 and tomcat 5 in my web application.
The database is in server.
I want a simple backup utility in my application to backup the database and store in my specified folder location.

Can any one help me. I have seen lots of site to back database from java. But none of them is working.

Please help me with correct code.

Thanks Much.



ADD TO DEL.ICIO.US  ADD TO DIGG  ADD TO FURL  ADD TO NEWSVINE  ADD TO NETSCAPE 
ADD TO TECHNORATI FAVORITES  Technorati ADD TO SQUIDOO  ADD TO WINDOWS LIVE  ADD TO YAHOO MYWEB  ADD TO ASK 
ADD TO REDDIT  ADD TO STUMBLEUPON  ADD TO GOOGLE   

11-06-2007 08:35 PM
Find all posts by this user Quote this message in a reply
digz6666
Junior Member
**


Posts: 2
Group: Registered
Joined: Jun 2008
Status: Offline
Reputation: 0
Thank 0
0 was given thank in 0 posts
Post: #2
RE: MySQL 5.0 backup from java

sanjay_sharma77 Wrote:
I'm using mySQL 5.0 and tomcat 5 in my web application.
The database is in server.
I want a simple backup utility in my application to backup the database and store in my specified folder location.

Can any one help me. I have seen lots of site to back database from java. But none of them is working.

Please help me with correct code.

Thanks Much.


Try this

Code:
try {
    File backupFile = new File("backup_db.sql");
    String filePath = "\"" + backupFile.getAbsolutePath() + "\"";
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("mysqldump -uroot -ppass db_eonf --lock-all-tables --opt > " + filePath);
} catch (IOException ex) {
    ex.printStackTrace();
}



ADD TO DEL.ICIO.US  ADD TO DIGG  ADD TO FURL  ADD TO NEWSVINE  ADD TO NETSCAPE 
ADD TO TECHNORATI FAVORITES  Technorati ADD TO SQUIDOO  ADD TO WINDOWS LIVE  ADD TO YAHOO MYWEB  ADD TO ASK 
ADD TO REDDIT  ADD TO STUMBLEUPON  ADD TO GOOGLE   

This post was last modified: 06-07-2008 05:21 PM by digz6666.

06-07-2008 04:20 PM
Find all posts by this user Quote this message in a reply
digz6666
Junior Member
**


Posts: 2
Group: Registered
Joined: Jun 2008
Status: Offline
Reputation: 0
Thank 0
0 was given thank in 0 posts
Post: #3
RE: MySQL 5.0 backup from java

sanjay_sharma77 Wrote:
I'm using mySQL 5.0 and tomcat 5 in my web application.
The database is in server.
I want a simple backup utility in my application to backup the database and store in my specified folder location.

Can any one help me. I have seen lots of site to back database from java. But none of them is working.

Please help me with correct code.

Thanks Much.


Try this. This is working 100% fine!
This backs up db_eonf database to backup/backupScript.sql.
MySQL username discussed in this post is "root" and password is "pass".

Code:
try {
            Runtime runtime = Runtime.getRuntime();
            File backupFile = new File("backup/backupScript.sql");
            FileWriter fw = new FileWriter(backupFile);
            Process child = runtime.exec("mysqldump --user=root --password=pass --lock-all-tables --opt db_eonf");
            InputStreamReader irs = new InputStreamReader(child.getInputStream());
            BufferedReader br = new BufferedReader(irs);
            
            String line;
            while( (line=br.readLine()) != null ) {
                fw.write(line + "\n");
            }
            fw.close();
            irs.close();
            br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }



ADD TO DEL.ICIO.US  ADD TO DIGG  ADD TO FURL  ADD TO NEWSVINE  ADD TO NETSCAPE 
ADD TO TECHNORATI FAVORITES  Technorati ADD TO SQUIDOO  ADD TO WINDOWS LIVE  ADD TO YAHOO MYWEB  ADD TO ASK 
ADD TO REDDIT  ADD TO STUMBLEUPON  ADD TO GOOGLE   

This post was last modified: 06-07-2008 05:21 PM by digz6666.

06-07-2008 05:10 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Reset MySQL root password : Shital 0 196 02-14-2008 10:31 PM
Last Post: Shital
  Top best 84 MySql Performance tips! admin 0 331 12-11-2007 07:02 PM
Last Post: admin
  MySql Backup and restoring backup from Command Line admin 0 307 09-28-2007 11:16 PM
Last Post: admin
  10 tips for optimizing mysql queries admin 0 207 07-31-2007 07:53 PM
Last Post: admin

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: