Scripts for compressed export and import

From: Harkki Jukka <jht_at_cs.tut.fi>
Date: Wed, 22 Jun 1994 17:26:31 GMT
Message-ID: <1994Jun22.172631.4169_at_news.cs.tut.fi>


   Here are two UNIX Bourne shell scripts which make compressed    database exports and imports using Oracle Exp/Imp utilities.    Compression is done by background process and via temporary pipe.    The scripts take some general options explained below and normal    Oracle Exp/Imp parameters.

   Note: Feel free to use, copy, modify or to do anything with this

            script. However, if you find it useful - let me know it too.
            As usual, you are using these scripts totally on your own
            risk.

   Scripts are working at least with Sun OS 4.1.3 and Oracle 6.0.33 &    7.0.15, but there should be no major problems in other UNIX    environments. The compression method may vary.

   Usage: zexp [ -d database SID ] [ -f dump file ] [ -l log file ]

               [ -p parameter file ] [ usr/pwd ] options...
      or
          zimp [ -d database SID ] [ -f dump file ] [ -l log file ]
               [ -p parameter file ] [ usr/pwd ] options...

   Where: -d names the database at /etc/oratab
          -f names the output/input dump file
          -l names the log file
          -p names the parameter file
          usr/pwd is a normal username/password combination
          options are normal parameters given to Oracle Exp/Imp


   To export ones tables:

      zexp scott/tiger

   Scripts work also with tapes so you can make an export directly    to tape. This exports the hole database:

      zexp -f /dev/rst0 system/manager full=y

   You can also use normal Oracle Imp/Exp parameter files:

      zimp scott/tiger -p import.par

   Exit: 0 normal, successful operation

          1 problem with options or interrupted
          2 problem with files; parameter file does not exist
          3 problem with database; SID unknown or database not running


   Bugs:  Dump file definitions "file=" are not searched from nested
          parameter files.

          If for some reason (help=y) Oracle Exp won't write anything
          to the pipe, compression process won't read EOF, and the
          process won't die. For this reason there is a kill-statement
          with the trap to kill child processes when you cancel script
          with ^C.


   Author: Jukka Harkki

   E-Mail:  jht_at_cs.tut.fi      Address: Joinex Oy
                                        Pyhajarvenkatu 5 B
                                        33200 TAMPERE
                                        FINLAND

  • CUT HERE zexp --- CUT HERE zexp --- CUT HERE zexp --- CUT HERE zexp --- :
    #
    # Compressed database export.
    #
    # Usage: zexp [ -d database SID ] [ -f dump file ] [ -l log file ]
    # [ -p parameter file ] [ usr/pwd ] options...
    #
    # Where: -d names the database at /etc/oratab
    # -f names the output dump file
    # -l names the log file
    # -p names the parameter file
    # usr/pwd is a normal username/password combination
    # options are normal parameters given to Oracle Exp
    #
    # Exit: 0 normal, successful operation
    # 1 problem with options or interrupted
    # 2 problem with files; parameter file does not exist
    # 3 problem with database; SID unknown or database not running
    #
    # Author: Jukka Harkki jht_at_cs.tut.fi

ME="zexp"
MKNOD="/usr/etc/mknod"

ORATABLE="/etc/oratab" # Defaults; modify these if necessary PIPE_FILE="/tmp/$ME.$$"

DMP_FILE="expdat"
DMP_EXT="dmp.Z"
LOG_EXT="log"


# Trap interruptions and kill compression process before exiting
trap 'kill -9 $!; exit 1' 1 2 3 15

# Parameter handling

while [ $# -gt 0 ]; do

   case $1 in

      -d)  DATABASE=$2
           shift 2
           ;;
      -f)  DMP_FILE=$2
           shift 2
           ;;
      -l)  LOG_FILE=$2
           shift 2
           ;;
      -p)  PARAMETER_FILE=$2
           shift 2
           ;;
      *=*) # search for "file=" parameter from options
           IFILE=`echo $1 | grep -i "^file=" | cut -d= -f2`
           if [ "$IFILE" ]; then
              DMP_FILE=$IFILE
           fi
           OPTIONS="$OPTIONS $1"
           shift
           ;;
      */*)
           USERID="userid=$1"
           shift
           ;;
      *)
           echo $ME: unknown parameter $1
           exit 1
           ;;

   esac
done

# We need some options to do something
if [ ! "$PARAMETER_FILE" -a ! "$OPTIONS" -a ! "$USERID" ]; then

   echo "Usage: $ME [ -d database SID ] [ -f dump file ] [ -l log file ]"    echo " [ -p parameter file ] options..."    exit 1
fi

# Check that given parameter file exists and search for "file=" statement
if [ "$PARAMETER_FILE" ]; then

   if [ ! -f "$PARAMETER_FILE" ]; then

      echo $ME: parameter file $PARAMETER_FILE does not exist.
      exit 2
   else
      IFILE=`grep -i "^file=" $PARAMETER_FILE | cut -d= -f2`
      if [ "$IFILE" ]; then
         DMP_FILE="$IFILE"
      fi
      PARAMETER_OPT="parfile=$PARAMETER_FILE"
   fi
fi

# Complete log file with default extension
case $LOG_FILE in

   *.*) ;;
   *) LOG_FILE="$LOG_FILE.$LOG_EXT"
esac

# Complete normal dump file with default extension
if [ ! -b "$DMP_FILE" -a ! -c "$DMP_FILE" ]; then

   case $DMP_FILE in

      *.*)  ;;
      *)    DMP_FILE="$DMP_FILE.$DMP_EXT"
   esac
fi

# Check selected SID and set ORACLE_SID & ORACLE_HOME
if [ "$DATABASE" ]; then

   ORACLE_HOME=`grep "^$DATABASE:" $ORATABLE | cut -d: -f2` ; export ORACLE_HOME    if [ ! "$ORACLE_HOME" ]; then

      echo $ME: unknown database SID $DATABASE
      exit 3

   fi
   ORACLE_SID=$DATABASE; export ORACLE_SID fi

# Is the selected database running?

if [ ! -f "$ORACLE_HOME/dbs/sgadef$ORACLE_SID.dbf" ]; then

   echo $ME: database $ORACLE_SID:$ORACLE_HOME is not running.    exit 3
fi

# Make a pipe for compressing and start compressing process reading that
# pipe. Character and block mode files are piped through dd to get output
# record length fixed

$MKNOD $PIPE_FILE p
if [ -b "$DMP_FILE" -o -c "$DMP_FILE" ]; then

   compress -c < $PIPE_FILE | dd of=$DMP_FILE conv=sync,block 2> /dev/null & else

   compress -c < $PIPE_FILE > $DMP_FILE & fi

# Start exporting to the compression pipe. Note the order of
# the parameters to ensure that the pipe gets the output
exp $PARAMETER_OPT $OPTIONS $USERID file=$PIPE_FILE 2>&1 | tee $LOG_FILE

# Wait for the compression process to finish and remove the
# temporary pipe

wait
rm $PIPE_FILE

# Exit successfully

exit 0
--- CUT HERE zimp --- CUT HERE zimp --- CUT HERE zimp --- CUT HERE zimp --- :
#
# Compressed database import.
#
# Usage: zimp [ -d database SID ] [ -f dump file ] [ -l log file ]
# [ -p parameter file ] [ usr/pwd ] options...
#
# Where: -d names the database at /etc/oratab
# -f names the input dump file
# -l names the log file
# -p names the parameter file
# usr/pwd is a normal username/password combination
# options are normal parameters given to Oracle Imp
#
# Exit: 0 normal, successful operation
# 1 problem with options or interrupted
# 2 problem with files; parameter file does not exist
# 3 problem with database; SID unknown or database not running
#
# Author: Jukka Harkki jht_at_cs.tut.fi

ME="zimp"
MKNOD="/usr/etc/mknod"

ORATABLE="/etc/oratab" # Defaults; modify these if necessary PIPE_FILE="/tmp/$ME.$$"

DMP_FILE="expdat"
DMP_EXT="dmp.Z"
LOG_EXT="log"


# Trap interruptions and kill compression process before exiting
trap 'kill -9 $!; exit 1' 1 2 3 15

# Parameter handling

while [ $# -gt 0 ]; do

   case $1 in

      -d)  DATABASE=$2
           shift 2
           ;;
      -f)  DMP_FILE=$2
           shift 2
           ;;
      -l)  LOG_FILE=$2
           shift 2
           ;;
      -p)  PARAMETER_FILE=$2
           shift 2
           ;;
      *=*) # search for "file=" parameter from options
           IFILE=`echo $1 | grep -i "^file=" | cut -d= -f2`
           if [ "$IFILE" ]; then
              DMP_FILE=$IFILE
           fi
           OPTIONS="$OPTIONS $1"
           shift
           ;;
      */*)
           USERID="userid=$1"
           shift
           ;;
      *)
           echo $ME: unknown parameter $1
           exit 1
           ;;

   esac
done

# We need some options to do something
if [ ! "$PARAMETER_FILE" -a ! "$OPTIONS" -a ! "$USERID" ]; then

   echo "Usage: $ME [ -d database SID ] [ -f dump file ] [ -l log file ]"    echo " [ -p parameter file ] options..."    exit 1
fi

# Check that given parameter file exists and search for "file=" statement
if [ "$PARAMETER_FILE" ]; then

   if [ ! -f "$PARAMETER_FILE" ]; then

      echo $ME: parameter file $PARAMETER_FILE does not exist.
      exit 2
   else
      IFILE=`grep -i "^file=" $PARAMETER_FILE | cut -d= -f2`
      if [ "$IFILE" ]; then
         DMP_FILE="$IFILE"
      fi
      PARAMETER_OPT="parfile=$PARAMETER_FILE"
   fi
fi

# Complete log file with default extension
case $LOG_FILE in

   *.*) ;;
   *) LOG_FILE="$LOG_FILE.$LOG_EXT"
esac

# Search normal dump file with bare name and extended name.
if [ ! -b "$DMP_FILE" -a ! -c "$DMP_FILE" ]; then

   if [ ! -f "$DMP_FILE" ]; then

      if [ ! -f "$DMP_FILE.$DMP_EXT" ]; then
         echo $ME: import file $DMP_FILE does not exist.
         exit 2
      else
         DMP_FILE="$DMP_FILE.$DMP_EXT"
      fi

   fi
fi

# Check selected SID and set ORACLE_SID & ORACLE_HOME
if [ "$DATABASE" ]; then

   ORACLE_HOME=`grep "^$DATABASE:" $ORATABLE | cut -d: -f2` ; export ORACLE_HOME    if [ ! "$ORACLE_HOME" ]; then

      echo $ME: unknown database SID $DATABASE
      exit 3

   fi
   ORACLE_SID=$DATABASE; export ORACLE_SID fi

# Is the selected database running?

if [ ! -f "$ORACLE_HOME/dbs/sgadef$ORACLE_SID.dbf" ]; then

   echo $ME: database $ORACLE_SID:$ORACLE_HOME is not running.    exit 3
fi

# Make a pipe for uncompressing and start uncompressing process reading that
# pipe. Character and block mode files are piped through dd to get input
# record length variable again

$MKNOD $PIPE_FILE p
if [ -b "$DMP_FILE" -o -c "$DMP_FILE" ]; then

   (dd if=$DMP_FILE conv=unblock 2> /dev/null) | uncompress -c > $PIPE_FILE & else

   uncompress -c < $DMP_FILE > $PIPE_FILE & fi

# Start exporting to the compression pipe. Note the order of
# the parameters to ensure that the pipe gets the input
imp $PARAMETER_OPT $OPTIONS $USERID file=$PIPE_FILE 2>&1 | tee $LOG_FILE

# Wait for the compression process to finish and remove the
# temporary pipe

wait
rm $PIPE_FILE

# Exit successfully

exit 0
--- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE ---

-- 
//
//  Jukka Harkki   Net: jht_at_cs.tut.fi      Addr: Joinex Oy
//                 Tel: +358 31 222 4680         Pyh{j{rvenkatu 5B
//                 Fax: +358 31 222 4685         33200 TAMPERE, FINLAND
Received on Wed Jun 22 1994 - 19:26:31 CEST

Original text of this message