Friday, October 25, 2013

Script: Shell Script to export Full DB or Single or Multiple Schemas

Just recently I have written below script for export full database or single/multiple schemas.

Follow the steps in comments section.

#!/bin/bash
###################################################################################################** Logical Database/Schema's backup Script**###########################
############## **Chowdari's Oracle DBA Blog - mbc-dba.blogspot.com ** ####################
########################################################################################################## Please create exp_user and provide grants #######################
# create user EXP_USR identified by EXP_USR;                                                                             #####
# grant CONNECT,EXP_FULL_DATABASE,IMP_FULL_DATABASE to EXP_USR;           #######
#################################################################################
# If you want schema wise backup, Please add list of schemas with single space otherwise                
# keep it blank.  Follow below examples                                                              ###################
# Example for schemawise backup: SchemaName=(ABC XYZ MNO) - Here ABC,XYZ, MNO are  ### #  schema names                                                                                                        ################
# Example for full db backup: SchemaName=()                                                          ################
#################################################################################
# Please assign database name in SID variable. Example I have given TESTDB            ###############
#################################################################################  

SID=TESTDB
BKP_LOCATION=`pwd`
SchemaName=(CRM EMP)
#SchemaName=()
SchLen=${#SchemaName[@]}

if [ ${SchLen} -eq 0 ]; then
 exp EXP_USR/EXP_USR@$SID FILE=$BKP_LOCATION/EXP_FULL.DMP LOG=$BKP_LOCATION/EXP_FULL.LOG FULL=Y STATISTICS=NONE
else
 echo "Schema Bkp"
 for (( i = 0; i <= `expr ${SchLen} - 1`; i++ ))
 do
  exp EXP_USR/EXP_USR@$SID FILE=$BKP_LOCATION/${SchemaName[$i]}_EXP.DMP LOG=$BKP_LOCATION/${SchemaName[$i]}_EXP.LOG OWNER=${SchemaName[$i]} STATISTICS=NONE
 done
fi


Hope this will help you... :)

Best Regards,

4 comments:

  1. Hi,

    while executing the script I am getting the error
    EXP-00056: ORACLE error 1455 encountered
    ORA-01455: converting column overflows integer datatype
    EXP-00000: Export terminated unsuccessfully
    ..
    What to do ???

    ReplyDelete
  2. Hi Deepak, Thanks for using this script.

    In above script u need to change SID (give ur db service name) and If u want to export schema wise, then modify SchemaName=() parameter.

    I have tested in my environment.. Hope it will work in ur env..

    Thanks
    Chowdari

    ReplyDelete
  3. Chowdari

    Do you by chance have an import sceript like this one. Used the export script, and it worked well.

    Thanks.

    ReplyDelete
  4. how to take multiple schema name from user and check in DB that its exist and then after implement in EXPDP command

    ReplyDelete

Some Most Popular Articles