In this post we are going to see how to take the backup of source code in a text file. All you have to do write a small piece of code. You can check the source code in DBA_SOURCE view (or ALL_SOURCE). In the following procedure we are going to use the same view to get the code.
Sample Code :-
That’s it execute the above procedure (EXEC BACKUP_SOURCE_CODE) and the file (bkup_source_code.sql) will be created OP_DATA_DIR directory.
I did the test run of the procedure and found it take 17 second to take backup of more than 200 procedure in oracle 11G R2.
As you can see here only procedure are taken as backup, you can modify the cursor ‘source_info‘ and you can include the Function, Package, Index, Trigger etc.
And another thing to run this procedure you should have access for oracle directories and UTL_FILE utilities. For this you need to do create a oracle directory as
CREATE OR REPLACE DIRECTORY OP_DATA_DIR AS ‘/home/data_bkup’
Usage : –
Well their are lot of source code controller available but this tool comes handy if you have to move the code from one database to another database.
So till next time bye.