aspose file tools*
The moose likes JDBC and the fly likes Back Up & Restore Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Back Up & Restore Database" Watch "Back Up & Restore Database" New topic
Author

Back Up & Restore Database

Feyna Reendrina
Greenhorn

Joined: Apr 18, 2006
Posts: 11
i want to make a application that have some facilities like back up and restore database....

i make the application using java and netbeans as GUI
and i use mysql as my database....

can you help me, hor to back up and restore mysql database in java language..


thx
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Why do you want to do this? Is this a school project? Because there lots of tools already for this type of thing.

The best way to backup and restore a MySQL database would be the following.

1) Make your program that can run SQL script files (files full of SQL statements).

To backup

2) Dump the table definitions (as CREATE TABLE statements) and data (INSERT statements) into files.

3) Possibly zip resultant SQL files.

To restore

4) Possibly unzip SQL files.

5) execute SQL file
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Originally posted by Maximilian Xavier Stocker:
Why do you want to do this? Is this a school project? Because there lots of tools already for this type of thing.



Like the one that comes with it...
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html
Feyna Reendrina
Greenhorn

Joined: Apr 18, 2006
Posts: 11
i need it for my database project, where is can be have large record or database...

so i think, is it take time if i use max's method???
is you means that i must list all record in database (INSERT) and the table (TABLE)??? is it will take time for large database???

i have been tried the example (MySqlHotCopy.java) at
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html

but it doesn't work....
when i try to get the packages
at
http://www.kickjava.com/src/org/apache/commons/io/FileUtils.java.htm
but i can find what are IOUtils and CopyUtils ?? (i have been download all import packages)

beside that, directory source is input by user....
can we get it automatically??? (in mySQL)
example using registry like in Delphi??

Can you help me??


thanks you very much,...
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
It will take the time it takes. Even the utility I listed does the same thing I suggested so there is no other way then creating CREATE TABLE and INSERT statements and executing them to restore.

You cannot just copy the files. This is a bad idea unless you are prepared to stop the database. Because otherwise you won't know if the files are in a cohesive state. Actually it's a bad idea anyway because the table files could be corrupted and then you'd just be backing up a corrupted file.

Best way is to create the insert statements. You can write this yourself or use the tools provided. You can always execute other programs through Runtime.exec
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
But again there will be no shortcuts and if performance is an issue then I would suggest choosing a better (non-toy) database than MySQL. MySQL is a good example of you get what you pay for.
 
Don't get me started about those stupid light bulbs.
 
subject: Back Up & Restore Database