aspose file tools*
The moose likes JDBC and the fly likes Take backup from MYSQL through java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Take backup from MYSQL through java" Watch "Take backup from MYSQL through java" New topic
Author

Take backup from MYSQL through java

prathana balaji
Ranch Hand

Joined: Oct 07, 2007
Posts: 30
Hi all,
Please someone help me --How to take backup automatically from the database(MYSQL) after certains number of records from java GUI.
When the record count exceeds certain count then the records should move from the table to backup.

Regards,
Prathana
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30957
    
158

Prathana,
Do you know the command line to do a backup from mySql? If so, you could call this from Java using Runtime.exec()


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
MySQL has a deprecated function for backing up a single table.

BACKUP TABLE tbl_name [, tbl_name] ... TO '/path/to/backup/directory'

But keep in mind... this is a very poor way to back up your data in a relational database.

You would be better served by determining a way to handle time variancy in your table's structure
prathana balaji
Ranch Hand

Joined: Oct 07, 2007
Posts: 30
thanks a lot.
jeanne,I know the command line that is given in sql command line
mysqldump -a -u root -p dbname > dbname.sql
How can I call that in java using Runtime.exec()?
Can you please explain me ...

Thanks in advance

Regards
Parthana
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Originally posted by prathana balaji:
mysqldump -a -u root -p dbname > dbname.sql
How can I call that in java using Runtime.exec()?


[ November 30, 2007: Message edited by: Rob Prime ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Isuru Ranawaka
Greenhorn

Joined: Jan 13, 2013
Posts: 2
Hi everyone, I created a solution myself. Please take a look and get if you think it will be useful.

This is in reply to this from Prarthana balaji.
prathana balaji wrote:Hi all,
Please someone help me --How to take backup automatically from the database(MYSQL) after certains number of records from java GUI.
When the record count exceeds certain count then the records should move from the table to backup.

Regards,
Prathana


It is not a complex solution, I used some SHOW CREATE and SELECT commands and parsed the strings.
I Tried to make it look alike to a backup you take from Navicat software.
Here is the code.


Full usable 8.java file can be found here. http://isuru.diyatha.com/java-db-dump/
 
Don't get me started about those stupid light bulbs.
 
subject: Take backup from MYSQL through java