Pavan DBA's Blog

The DBA Knowledge Store

Script for HOT Backup in Unix

Posted by Pavan DBA on March 8, 2012


###############

HOT BACKUP IN UNIX

###############

#!/bin/ksh

# —————————————————————————–

# —————————————————————————–

# — Description: Oracle Online (Hot) Backup Job —

# — —

# — Instructions: —

# — 1) Create the following directories if not already setup: —

# — backups —

# — backups/common_scripts (For common scripts only – —

# — Do not change these scripts or add user scripts —

# — to this directory. Common scripts will be —

# — distributed from a master copy on a regular —

# — basis) —

# — backups/jobs —

# — backups/joblogs —

# — backups/adsmlogs —

# — backups/recv ( for recovery scripts generated) —

# — backups/scripts ( for userexit scripts) —

# — —

# — 2) Change variables below as needed —

# — —

# — 3) In the Main Section, uncomment the common functions —

# — you what executed —

# — —

# —————————————————————————

# ———— variables common to instance ——————————

ORACLE_HOME=/d001/oracle/9.2.0

LD_LIBRARY_PATH=$ORACLE_HOME/lib

ORACLE_SID=SDSS # oracle instance

BACKUP_DIR=/d002/oracle/$ORACLE_SID/backups # backup scripts, logs, etc…

COMMON_DIR=/d002/oracle/common/backups # backup scripts, logs, etc…

UID=”system/systemSDSS” # userid/password to be

# used with sqlplus queries

RETPRD=7 # how many days do you

# want to keep joblogs etc..

ADSM_PROCESS_LIMIT=15 # max adsm processes

TS_PROCESS_LIMIT=12 # max ts in bkup mode

SLEEP_TIME=60 # sleep time after limits

#ADSM_SERVER=”-se=mvsosap” # adsm server – leave commented

# for default

#MGMTCLASS=”-ARCHMc=UNIX_MGT” #adsm management class –

# leave commented for default

#FROMNODE=”-fromnode=`hostname`” #adsm fromnode parameter –

# leave commented for default

#FROMOWNER=”-fromowner=`whoami`” #adsm fromowner parameter –

# leave commented for default

SQLDBA=”sqlplus” # use “svrmgrl” for v7.3

INITDF=$ORACLE_HOME/dbs/init$ORACLE_SID.ora # init.ora to be copied

#CONFIGDF=$ORACLE_HOME/dbs/config$ORACLE_SID.ora # config.ora to be copied

# ———– sendtrap variables ——————————

SNDTRP_FLG=N # do you want to use

# sendtrap (Y,N)

# if you are using sendtrap

# change the following

# VARx’s to instruct

# operations what to do

VAR1=”….Hot Backup”

VAR2=$ORACLE_SID

VAR3=”Database is down – Qname= – contact oncall DBAORA”

VAR4=”Compress error – Qname= – contact oncall DBAORA”

VAR5=”Copy error – Qname= – contact oncall DBAORA”

VAR6=”ADSM error – Qname= – contact oncall DBAORA”

VAR7=”DB already in bkup mode – Qname= – contact oncall DBAORA”

export COMMON_DIR ORACLE_HOME ORACLE_SID UID VAR3 VAR4 VAR5 VAR6 VAR7 RETPRD

export INITDF CONFIGDF MGMTCLASS BACKUP_DIR ADSM_SERVER SQLDBA VAR1 VAR2

export FROMOWNER FROMNODE ADSM_PROCESS_LIMIT TS_PROCESS_LIMIT SLEEP_TIME

export LD_LIBRARY_PATH

# ————————————————————————–

# ———– variables common to server ——————————

HOTBKUPDIR=$BACKUP_DIR/joblogs # backup df dest

ALRTPATH=/d002/oracle/$ORACLE_SID/dumpb # alert log path

TRCDIR=/d002/oracle/$ORACLE_SID/dumpu # trace file path

ARCHDIR=/d801/oracle/$ORACLE_SID/archive # archive log directory

DSMPATH=/usr/bin # dsmc command path

STPATH=/usr/local/bin # sendtrap path

TMP=/tmp # temp directory

export HOTBKUPDIR ALRTPATH ARCHDIR TRCDIR DSMPATH STPATH TMP

# —————————————————————————–

# ————— variables common to backup processes ————————

BKUP_JOB_LOGS=$BACKUP_DIR/joblogs # job log destination

BKUP_ADSM_LOGS=$BACKUP_DIR/adsmlogs # adsm log destination

BKUP_RECV_SCRIPTS=$BACKUP_DIR/recv # recov script dest

BKUP_RETR_SCRIPTS=$BACKUP_DIR/recv # adsm retr script dest

BKUP_COMMON_SCRIPTS=$COMMON_DIR/common_scripts # common script dest

CNTLTRC=$BACKUP_DIR/recv # cntl to trace dest

FILELST=$BKUP_JOB_LOGS # file list dest

DBF_LIST=$BKUP_JOB_LOGS # datafile only des

# used for cloning

VERSION=prod # versions of the script

# prod = production

# devl = development

# qlty = quality

EXIT_0=”$BACKUP_DIR/scripts/exit_0.sh” # exit 0 routine – successful

EXIT_4=”$BACKUP_DIR/scripts/exit_4.sh” # exit 4 routine – warning

EXIT_8=”$BACKUP_DIR/scripts/exit_8.sh” # exit 8 routine – error

USER_EXIT_1=”$BACKUP_DIR/scripts/usrexit5.sh” # user exit dest

USER_EXIT_2=”$BACKUP_DIR/scripts/usrexit6.sh”

USER_EXIT_3=”$BACKUP_DIR/scripts/usrexit7.sh”

USER_EXIT_4=”$BACKUP_DIR/scripts/usrexit8.sh”

ARCH_BKUP_JOB=”$BACKUP_DIR/jobs/arch_$ORACLE_SID.job”

JDATE=`date +%y%j`

CTIME=`date +%HH%MM%SS`

export BKUP_JOB_LOGS BKUP_RECV_SCRIPTS BKUP_RETR_SCRIPTS BKUP_COMMON_SCRIPTS

export CNTLTRC FILELST DBF_LIST VERSION EXIT_0 EXIT_4 EXIT_8

export JDATE CTIME USER_EXIT_1 USER_EXIT_2 USER_EXIT_3 USER_EXIT_4

export ARCH_BKUP_JOB

# ————————————————————————–

# ————– Main Section ——————————————-

. $BKUP_COMMON_SCRIPTS/hot_$VERSION.sh # read in common functions

# ————————————————————————–

# —– Uncomment the functions to be executed —————————–

param_set # set parameters for function – required

db_status # check database status

#user_exit_1 # user exit routine

move_alert_log # moves alert log to timestamped dataset

check_bkup_mode # check for tablespaces already in backup mode

#dbfiles_for_cloning # create list of database files for cloning

get_tsnames # get files to backup

#user_exit_2 # user exit routine

switch_logfiles # alter system switch logfiles

arch_log_list # record current active log list in joblog

#compress_df # compress files to backup directory

#copy_df # copy files to backup directory

df_to_adsm # archive files directly to ADSM

#user_exit_3 # user exit routine

#bkupdir_to_adsm # archive files in backup directory to ADSM

#dfadds_to_adsm # archive datafiles added since last backup

#user_exit_4 # user exit routine

switch_logfiles # alter system switch logfiles

arch_log_list # record current active log list in joblog

execute_arch_bkup # execute your Archive backup job

# To use this function, you MUST include an

# ARCH_BKUP_JOB variable in this job pointing

# to your Archive Backup Job to be executed.

#cleanup_archive_dir # remove old archive logs from archive log directory

cntl_to_trace # backup control file to trace and archive to ADSM

cntl_to_bkupdir # backup control file to bkup directory and arch to ADSM

clean_up # clean up directorys

save_to_adsm # archive joblogs, alert logs, recovery scripts and

# filelist to ADSM

create_stats # generate statistics for this backup

exit_0 # Backup successful routine

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: