Tuesday, February 17, 2009

Script to export/import oracle schema

Here is the bash script that does the job of export and import of an oracle schema to another schema.

Save this file as EXPORT_IMPORT.

For exporting the schema type
EXPORT_IMPORT EXP

This file generates the schema dump in exp_database.dmp file and it also makes log of export process in exp_database.log file.

For importing the same exported exp_database.dmp dump file to another schema type
EXPORT_IMPORT IMP

if [ $# -lt 1 ]; then
echo "First argument to this file should be either EXP or IMP."
exit
fi
if [ "$1" = "EXP" ]; then
if [ $# != 2 ]; then
echo "No of arguments to this file should be two."
echo "USAGE: EXPORT_IMPORT EXP "
exit
fi
exp "$2" FILE=exp_database.dmp COMPRESS=N CONSISTENT=N CONSTRAINTS=Y GRANTS=Y INDEXES=Y RECORD=Y ROWS=Y Feedback=1000 LOG=exp_database.log
fi
if [ "$1" = "IMP" ]; then
if [ $# != 3 ]; then
echo "No of arguments to this file should be three."
echo "USAGE: EXPORT_IMPORT IMP "
exit
fi
from_user=`echo "$2" | cut -f1 -d'/'`
to_user=`echo "$3" | cut -f1 -d'/'`
imp userid="$3" fromuser="$from_user" touser="$to_user" file=exp_database.dmp buffer=64000 commit=y
fi

Sphere: Related Content

0 comments: