Today I'm sharing script export_data.sh , it's included in the database administration bundle I'm using in day to day database administration activities. you can download the whole bundle from here:
http://dba-tips.blogspot.ae/2014/02/oracle-database-administration-scripts.html
This script gives you the option to export Full Database, Schema or table and also gives you the freedom of choosing between the Legacy export utility exp or using the modern Data pump utility expdp.
This script was tested on 10g, 11g and 12c versions on Linux & SUN environments.
How to use the script:
First download the script from here:
https://www.dropbox.com/s/h9gs6oz7lkar9as/export_data.sh?dl=0
Second run the script, if you have multiple running database on the server it will give you the option to select the database you want to export data from.
> It will ask you the location you want to save the dump file
> It will ask you if you want to export a SCHEMA.
>It will go into the export table mode:
[Enter the Owner then
- When EXPDP is used to export data, it will automatically calculate the degree of parallelism based on the number of core CPUs on the server .
- It will create user DBA_BUNDLEEXP7 granting it dba privilege to use it in the export
(I'm creating this user because using a sysdba user will disable functions like consistent=y during the
export)
- It will create a directory called EXPORT_FILES_DBA_BUNDLE pointing to the dump location
you've entered earlier [this in case you selected expdp utility to perform the export job].
- It will create a "BEFORE IMPORT SCRIPT" [In case you selected export Schema mode earlier]
this script will include the [creation statement of roles assigned to the user, user creation statement,
grant privileges/roles, grant privileges the user has on other schemas objects.
- It will create an "AFTER IMPORT SCRIPT" [In case you selected export Database mode earlier]
this script will hint you all triggers owned by SYS user [if exist]. These triggers will not be created
during the import process.
- It will create an "AFTER IMPORT SCRIPT" [In case you selected export Schema mode earlier]
this script will include the [creation statements of public synonyms for user;s table [if exist],
grant privileges on schema objects to other users [if exist], giving you a hint for the triggers owned
by other users that pointing to the exported schema tables [if exist], recompile invalid objects.
- It will create an "AFTER IMPORT SCRIPT" [In case you selected export Table mode earlier]
this script will create the public synonyms for exported table [if exist].
- The script will start the export job using DBA_BUNDLEEXP7 user.
- Once the export job finish it will drop the DBA_BUNDLEEXP7 user.
- At the end the script will list to you "Import Guidelines" including the
BEFORE/AFTER import scripts locations. Finally it will print the full path of the dumpfile.
If you still not OK with that introduction don't worry the script is self explanatory :-)
Please note that the COMPRESSION option is used during the export.
At any stage you can terminate the script by pressing [Ctrl+c]
DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
The following is the code: [in case the download link is not working]
http://dba-tips.blogspot.ae/2014/02/oracle-database-administration-scripts.html
This script gives you the option to export Full Database, Schema or table and also gives you the freedom of choosing between the Legacy export utility exp or using the modern Data pump utility expdp.
This script will not do the export job only , but it will help you in the import process later [when you import the dumpfile] by creating SQL scripts help you to create the objects and grant the privileges/roles the import process will skip, that function I consider the most useful function in this script.
This script was tested on 10g, 11g and 12c versions on Linux & SUN environments.
How to use the script:
First download the script from here:
https://www.dropbox.com/s/h9gs6oz7lkar9as/export_data.sh?dl=0
Second run the script, if you have multiple running database on the server it will give you the option to select the database you want to export data from.
> It will ask you the location you want to save the dump file
> It will ask you if you want to export the FULL DATABASE.
WHERE TO SAVE THE EXPORT FILE [DUMPFILE]? [ENTER THE FULL PATH]
Do you want to EXPORT FULL DATABASE? [Y|N] [Y] [N TO EXPORT SCHEMA|TABLE]
[If your answer is "no"]> It will ask you if you want to export a SCHEMA.
Do you want to EXPORT a SCHEMA? [Y|N] [Y] [N If you want to EXPORT TABLE]
[If your answer is "no"]>It will go into the export table mode:
[Enter the Owner then
Please Enter the TABLE OWNER:
Enter the Table name]Please Enter the TABLE NAME:
> It will ask you to select the utility you want to perform the export with [expdp or exp]> Then let the script do the remaining steps:
WHICH EXPORT UTILITY YOU WANT TO USE: [1) DATAPUMP [EXPDP]]
====================================
1) DATAPUMP [EXPDP]
2) LEGACY EXPORT [EXP]
- When EXPDP is used to export data, it will automatically calculate the degree of parallelism based on the number of core CPUs on the server .
- It will create user DBA_BUNDLEEXP7 granting it dba privilege to use it in the export
(I'm creating this user because using a sysdba user will disable functions like consistent=y during the
export)
- It will create a directory called EXPORT_FILES_DBA_BUNDLE pointing to the dump location
you've entered earlier [this in case you selected expdp utility to perform the export job].
- It will create a "BEFORE IMPORT SCRIPT" [In case you selected export Schema mode earlier]
this script will include the [creation statement of roles assigned to the user, user creation statement,
grant privileges/roles, grant privileges the user has on other schemas objects.
- It will create an "AFTER IMPORT SCRIPT" [In case you selected export Database mode earlier]
this script will hint you all triggers owned by SYS user [if exist]. These triggers will not be created
during the import process.
- It will create an "AFTER IMPORT SCRIPT" [In case you selected export Schema mode earlier]
this script will include the [creation statements of public synonyms for user;s table [if exist],
grant privileges on schema objects to other users [if exist], giving you a hint for the triggers owned
by other users that pointing to the exported schema tables [if exist], recompile invalid objects.
- It will create an "AFTER IMPORT SCRIPT" [In case you selected export Table mode earlier]
this script will create the public synonyms for exported table [if exist].
- The script will start the export job using DBA_BUNDLEEXP7 user.
- Once the export job finish it will drop the DBA_BUNDLEEXP7 user.
- At the end the script will list to you "Import Guidelines" including the
BEFORE/AFTER import scripts locations. Finally it will print the full path of the dumpfile.
If you still not OK with that introduction don't worry the script is self explanatory :-)
Please note that the COMPRESSION option is used during the export.
At any stage you can terminate the script by pressing [Ctrl+c]
DISCLAIMER: THIS SCRIPT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS".
The following is the code: [in case the download link is not working]