This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Kubernetes in Action and have Marko Luksa on-line!
See this thread for details.
Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Take backup from MYSQL through java  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
author & internet detective
Marshal
Posts: 37714
579
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prathana,
Do you know the command line to do a backup from mySql? If so, you could call this from Java using Runtime.exec()
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 21187
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!