Logo

UNIX Shell Script

Full Database Export

 

Updated : 29-July-1998
Version : 1.0

Description

Full database export and compress using named pipes. Use the full database import script to import the data back.

Parameters

$1 (MANDATORY) - ORACLE_SID of the database to export
$2 (MANDATORY) - The directory of the compressed export file
$3 (MANDATORY) - The database connect string to export from.

Shell Source

#!/bin/ksh
DATABASE=$1
DUMPDIR=$2
USERPASS=$3
# Check that we have a database to start
if [ -z "${DATABASE}" ]
then
   echo
   echo "No Database Specified !"
   echo
   echo "Usage : fulldbexport.ksh <ORACLE_SID> <DUMPDIR> <CONNECT STRING>"
   echo
   echo "where ORACLE_SID (Mandatory) - SID of database to start"
   echo "      DUMPDIR - Directory of the compressed export file"
   echo "      CONNECT - Username/Password of the database user to export from."
   echo
   echo " e.g.  $ fulldbexport.ksh PROD /dbexport system/manager" 
   echo
   exit 1
fi
# Check the dump directory exists
if [ ! -d "${DUMPDIR}" ]
then
  echo
  echo "$DUMPDIR does not exist !"
  echo
  exit 1
fi
# Check we have an Oracle username and password
if [ -z "${USERPASS}" ]
then
   echo
   echo "No Database connect string specified !"
   echo
   echo "Usage : fulldbexport.ksh <ORACLE_SID> <DUMPDIR> <CONNECT STRING>"
   echo
   echo "where ORACLE_SID (Mandatory) - SID of database to start"
   echo "      DUMPDIR - Directory of the compressed export file"
   echo "      CONNECT - Username/Password of the database user to export from."
   echo
   echo " e.g.  $ fulldbexport.ksh PROD /dbexport system/manager" 
   echo
   exit 1
fi
# Get the ORACLE_HOME from the oratab file
ORACLE_HOME=`cat /etc/oratab | grep $DATABASE | awk -F: '{print $2}'`
if [ ! -d "${ORACLE_HOME}" ]
then
  echo
  echo "$ORACLE_HOME does not exist !"
  echo
  exit 1
fi
ORACLE_SID=$DATABASE
export ORACLE_SID
PATH=.:$ORACLE_HOME/bin:$PATH; export PATH
LOGFILE=$DUMPDIR/exp${ORACLE_SID}_full.log
PIPEFILE=$DUMPDIR/PIPE.dmp
# Check we have created the named pipe file, or else there is no point
# continuing
if [ ! -p ${PIPEFILE} ]
then
   echo
   echo "Create the named pipe file ${PIPEFILE} using "
   echo "   $ mknod p $DUMPDIR/PIPE.dmp"
   echo
   exit 1
fi
# Create a new empty logfile
exec >$LOGFILE 2>&1
echo
echo "*******************************************************"
echo "*     Exporting ${ORACLE_SID} database at `date`"
echo "*******************************************************"
echo

exp $USERPASS full=y consistent=y buffer=1000000 file=${PIPEFILE} | compress < ${PIPEFILE} > $DUMPDIR/exp${ORACLE_SID}_full.dmp.Z
echo
echo "*******************************************************"
echo "*     Export Completed at `date`"
echo "*******************************************************"
echo
exit 0

Return to Index of SQL Scripts


Home | Company Profile | Services | Contact Us | SQL scripts and tips | Quiz
Legal

Logo