echo ´date´ >> $LOGDIR/${ORA_SID}.log
echo "${ORA_SID}, import completed successfully" >> $LOGDIR/${ORA_SID}.log
####################### END MAIN ###############################
SplitImport Script under Unix Checklist
•
In the
main()function, set the correct values for the
BACKUPDIR,
ORATABDIR, and
TOOLSvariables highlighted in the import script. The default location of
ORATABDIRis different for each flavor of Unix.
•
Check for the existence of the
SIDin the
oratabfile. If not already there, you must add the instance.
•
List all split filenames in the
ZFILESvariable in the
main()function.
•
The
funct_build_parfile()function builds the parameter file. By default, it performs a full import. You can modify the settings to perform a user or table import.
Pass
SIDand
OWNERas parameters to the program:
funct_desplitcompress_pipe()
The only trick here is that we need to split and uncompress the files before we use them as input to import command. That is accomplished by creating two pipes. Here, we use the
catcommand to send output from split files to the split pipe device. The split pipe device is passed to the
uncompresscommand. The output from the
uncompresscommand is sent to the Oracle
importcommand.
catand
uncompressare Unix commands.
Everything else is the same as a regular import.
Oracle Software Backup
This section discusses backing up the software directories of Oracle. We have already discussed
how to back up the database. Backing up software is also a very important part of a backup
strategy. The software might not need to be backed up as often as the database because it does not
change quite as often. But as you upgrade, or before you apply any patches to existing software, it
is important to make a backup copy of it to avoid getting into trouble.
Listing 3.8 contains the script to perform a backup of Oracle software. The script takes two input parameters—
SIDand
OWNER.
SIDis the instance to be backed up, and
OWNERis the Unix account under which Oracle is running.
Listing 3.8
OraSoftware_ux#####################################################################
# PROGRAM NAME: OraSoftware_ux
# PURPOSE: Backup ORACLE_HOME & ORACLE_BASE
# USAGE: $OraSoftware_ux SID OWNER
# INPUT PARAMETERS: SID(Instance name), OWNER(Owner of instance)
#####################################################################
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# funct_verify_shutdown(): Verify that database is down
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
funct_verify_shutdown(){
STATUS=´ps -fu ${ORA_OWNER} |grep -v grep| grep ora_pmon_${ORA_SID}´
if [ $? = 0 ]; then
echo "´date´" >> ${LOGFILE}
echo "SOFTWAREBACKUP_FAIL: ${ORA_SID}, Database is up, can't do software backup if the database is online." |tee -a ${BACKUPLOGFILE} >>
${LOGFILE}
exit 1 fi
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# funct_shutdown_i(): Shutdown database in Immediate mode
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
funct_shutdown_i(){
${ORACLE_HOME}/bin/sqlplus -s << EOF / as sysdba
shutdown immediate;
exit EOF }
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# funct_startup_n(): Startup database in normal mode
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
funct_startup_n(){
${ORACLE_HOME}/bin/sqlplus -s << EOF / as sysdba
startup;
exit EOF }
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# funct_software_bkup(): Backup software
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
funct_software_bkup(){
echo "tarring ${ORA_HOME}" >> ${BACKUPLOGFILE}
echo "tarring ${ORA_BASE}" >> ${BACKUPLOGFILE}
nohup tar cvlpf - ${ORA_HOME} | compress > ${ORAHOMEFILE} 2> ${BACKUPLOGFILE}
nohup tar cvlpf - ${ORA_BASE} | compress > ${ORABASEFILE} 2> ${BACKUPLOGFILE}
#Prepare restore file
echo "zcat ${ORAHOMEFILE}| tar xvlpf - ${ORA_HOME}" > ${RESTOREFILE}
echo "zcat ${ORABASEFILE}| tar xvlpf - ${ORA_BASE}" >> ${RESTOREFILE}
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# funct_chk_parm(): Check for input parameters
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
funct_chk_parm() {
if [ ${NARG} -ne 2 ]; then
echo "SOFTWAREBACKUP_FAIL: ${ORA_SID}, Not enough arguments passed"
exit 1 fi
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# funct_chk_bkup_dir(): Create backup directories if not already exist
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
funct_chk_bkup_dir() {
RESTOREFILE_DIR="${BACKUPDIR}/restorefile_dir"
BACKUPLOG_DIR="${BACKUPDIR}/backuplog_dir"
SOFTWARE_DIR="${BACKUPDIR}/software_dir"
BACKUPLOGFILE="${BACKUPLOG_DIR}/backup_log_${ORA_SID}"
RESTOREFILE="${RESTOREFILE_DIR}/restorefile_${ORA_SID}"
ORAHOMEFILE="${SOFTWARE_DIR}/orahome_${ORA_SID}.tar.Z"
ORABASEFILE="${SOFTWARE_DIR}/orabase_${ORA_SID}.tar.Z"
LOGFILE="${LOGDIR}/${ORA_SID}.log"
if [ ! -d ${RESTOREFILE_DIR} ]; then mkdir -p ${RESTOREFILE_DIR}; fi if [ ! -d ${BACKUPLOG_DIR} ]; then mkdir -p ${BACKUPLOG_DIR}; fi if [ ! -d ${SOFTWARE_DIR} ]; then mkdir -p ${SOFTWARE_DIR}; fi if [ ! -d ${DYN_DIR} ]; then mkdir -p ${DYN_DIR}; fi
if [ ! -d ${LOGDIR} ]; then mkdir -p ${LOGDIR}; fi
# Remove old files
rm -f ${RESTOREFILE_DIR}/*
rm -f ${BACKUPLOG_DIR}/*
rm -f ${SOFTWARE_DIR}/*
echo "${JOBNAME}: software backup of ${ORA_SID} begun on ´date +\"%c\"´ "
>> ${BACKUPLOGFILE}
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# funct_get_vars(): Get environment variables
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
funct_get_vars(){
ORA_HOME=´sed /#/d ${ORATABDIR}|grep -i ${ORA_SID}|nawk -F ":" '{print $2}'´
ORA_BASE=´echo ${ORA_HOME}|nawk -F "/" '{for (i=2; i<=NF-2; i++) print "/"$i}'´
ORACLE_BASE=´echo $ORA_BASE|tr -d " "´
init_file=$ORA_HOME/dbs/init$ORA_SID.ora
ORACLE_HOME=${ORA_HOME}; export ORACLE_HOME ORACLE_SID=${ORA_SID}; export ORACLE_SID if [ x$ORA_HOME = 'x' ]; then
echo "SOFTWAREBACKUP_FAIL: Can't get ORACLE_HOME from oratab for
$ORA_SID"|
tee -a ${BACKUPLOGFILE} >> ${LOGFILE}
exit 1 fi
if [ ! -f $init_file ]; then
echo "SOFTWAREBACKUP_FAIL: int$ORA_SID.ora does not exist in ORACLE_HOME/dbs. Used by funct_startup_n to start database"|tee -a
${BACKUPLOGFILE} >> ${LOGFILE}
exit 1 fi
}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# funct_chk_unix_command_status(): Check the exit status of Unix command
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
funct_chk_unix_command_status() { if [ $? != 0 ]; then
echo "´date´" |tee -a ${BACKUPLOGFILE} >> ${LOGFILE}
echo "SOFTWAREBACKUP_FAIL: ${1}"| tee -a ${BACKUPLOGFILE} >> ${LOGFILE}
exit 1
# Set environment variables
BACKUPDIR="/u02/${ORA_SID}/software"
echo "Preparing to make software backup of ${ORA_SID}"
funct_chk_parm funct_chk_bkup_dir funct_get_vars funct_shutdown_i funct_verify_shutdown funct_software_bkup funct_startup_n
echo "${ORA_SID}, Software Backup Completed successfully on ´date +\"%c\"´ "
|tee -a ${BACKUPLOGFILE} >> ${LOGFILE}
######## END MAIN #########################