0

I have developed an Java Swing Application with MS-SQL Server database and now i want to provide backup and restore option in my java swing application that is on click of a button it should backup the database and restore the database any possibilities of how can i do it through java. please help

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Zaheer
  • 123
  • 5
  • 14

3 Answers3

1

Two ways to do that. Backup and restore are just sql commands so you'd do them just the same as as you'd do any other bit of sql, e.g. a sql insert statement, unfortunately you need to know a fair bit about the the system to just do them, and you'll get no progress indicator. Using SQLSMO is another possibility, not sure about hitting a .net dll from java though. You could use SQLDMO (pre.net), but you'll need to install the backwards compatibility tools, and you'll give yourself an upgrade headache as DMO (while it seems to work) is not supported from SQL2012. Both have an event you can tick a progress bar on, course if the back up is fairly quick you could get away with not bothering with that.

However, some more to think about. You can backup while the system is running, but then you'd don't have a clear point where the system was at when you did.

Restore requires exclusive access and a high level of privilege, so it's not something you hand out and you need to get everybody off the databases.

And last but far from least it would be very bad, if you inadvertently restored a version of the database that no longer matched the application....

Personally I'd say the people who were authorised to do this should be able to do it without your tool. Dumbing it down, means a lot of code to make sure they don't restore a sql2000 back up from the trial you put out eight versions ago.

We did something similar back up restore code is a bout 2% of the application. For instance we do a pre-backup check, using dbcc et al, to make sure they aren't successfully backing up a corrupt db...

Tony Hopkinson
  • 20,172
  • 3
  • 31
  • 39
  • Sir since i am new to Microsoft SQL Server i know only to create tables insert update and delete and writing procedures.So cud u please tell me the Step by Step Procedure of doing it – Zaheer Dec 27 '12 at 15:02
  • I donlt do java, but however you would execute a bit of sql from your code and the sql for backup is Backup Database [somedatabasename] To Disk = 'somefilename' There's a bit more to it, account needs backup permission to the db, and the account sql server is running as needs write permissions to the folder being used. It's not hard just needs a bit of setting up. It is very setup specific though, so you'll have to work it out on your system. – Tony Hopkinson Dec 27 '12 at 18:04
0

You can write a simple script to backup your database and invoke it from java.

Community
  • 1
  • 1
Nickmancol
  • 1,034
  • 7
  • 16
0

You really need to put a little effort in here.

Since you can connect to the database server already and send it SQL commands, read this for backing up using TSQL.

For database restore, read this.

You need to have the appropriate permissions and access to the hardware for this to work.

Mike
  • 3,186
  • 3
  • 26
  • 32