I'm currently using Oracle 11g R2 express edition. How can I back up my database using java application? Is it possible?
-
1If you have a jdbc Driver for that database, anything is possible. Do some research and come back.Sotirios Delimanolis– Sotirios Delimanolis2013-03-28 18:17:19 +00:00Commented Mar 28, 2013 at 18:17
-
Research failed before today evening. I didn't get any way to do it. How can I do it? I have JDBC Oracle driverThisara Ranawaka– Thisara Ranawaka2013-03-28 18:20:47 +00:00Commented Mar 28, 2013 at 18:20
-
2lets first ask why do you want to do it from java ? and is it necessary for you to use jdbc as you can run a simple export command from your programgiorashc– giorashc2013-03-28 18:21:10 +00:00Commented Mar 28, 2013 at 18:21
-
1Just find out what Oracle command you have to send to the database to back it up, then execute those commands with your driver.Sotirios Delimanolis– Sotirios Delimanolis2013-03-28 18:26:09 +00:00Commented Mar 28, 2013 at 18:26
2 Answers
It depends on what you mean with "backup". If you want to create a dump of the database, you can do that using the dbms_datapump package.
As it is a regular PL/SQL package it can easily be called through JDBC. The easiest thing is probably to send an anonymous PL/SQL block as a single statement.
Something like this:
String sql =
"DECLARE \n" +
" handle NUMBER; \n" +
"BEGIN \n" +
" handle := DBMS_DATAPUMP.OPEN(operation => 'EXPORT', job_mode => 'SCHEMA', job_name => USER||'_DUMP', version => 'COMPATIBLE'); \n" +
" dbms_datapump.add_file(handle => handle, filename => 'db_backup', directory => 'EXPDP_DIR'); \n" +
" dbms_datapump.metadata_filter(handle, 'SCHEMA_LIST', '''SCOTT'''); \n" +
" dbms_datapump.start_job(handle); \n" +
" dbms_datapump.detach(handle); \n" +
"END;";
Statement stmt = connection.createStatement();
stmt.execute(sql);
Note that I left out any error handling. Alternatively you can call each dbms_datapump procedure individually (using a CallableStatement)
The dump will will be written on the server, not on the client!
For more details please refer to the manual:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_datpmp.htm
Comments
Well, generally you can, because you can extract data and store SQL structure (tables, constraints, indices etc.) You may find useful this You can also use YAML format to store data.