Wednesday, May 25, 2016

Oracle : Script for Archive backup in Linux




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

ARCH BACKUP IN LINUX

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




#!/bin/ksh

# — Description: Oracle Archived Log Archival Job —

# — —

# — Instructions: —

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

# — These directories receive the various output files from —

# — this job.

# — $ORACLE_BASE/backups —

# — $ORACLE_BASE/backups/jobs —

# — $ORACLE_BASE/backups/joblogs —

# — $ORACLE_BASE/backups/adsmlogs —

# — —

# — 2) Create a directory under the directory where the archived —

# — redo logs are kept. Call this sub-directory “save”. —

# — —

# — 3) Change variables below as needed —

# — —

# — —

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

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

ORACLE_HOME=/d001/oracle/9.2.0

ORACLE_SID=SDSS # oracle instance

ARCHIVE_DIR=/d002/oracle/$ORACLE_SID/backups # job logs, scripts etc….

COMMON_DIR=/d002/oracle/common/backups # common scripts

UID=”system/systemSDSS” # userid/password for

# sqlplus queries

RETPRD=3 # how many days do you

# want to keep joblogs etc..

ADSM_PROCESS_LIMIT=9 # max adsm processes

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

# for default server

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

# leave commented for default

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

# leave commented for default

#FROMOWNER=”-fromowner=`/usr/ucb/whoami`” #adsm fromowner parameter –

# leave commented for default

SQLDBA=”sqlplus” # use svrmgr for v7.3

# ———– 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=”….Archive 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 in hot bkup mode – Qname= – contact oncall DBAORA”

export COMMON_DIR ORACLE_HOME ORACLE_SID UID VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 VAR7

export INITDF CONFIGDF ARCHIVE_DIR MGMTCLASS ADSM_SERVER RETPRD

export FROMOWNER FROMNODE ADSM_PROCESS_LIMIT SHUTDOWN_TIME_LIMIT

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

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

ARCHIVELOGDIR=/d801/oracle/$ORACLE_SID/archive # archived log dest

ARCHIVELOGSAVEDIR=$ARCHIVELOGDIR/save # dest to save archived

# logs that have been sent

# to TSM

ARCHIVELOGFMT=”arch_*_$ORACLE_SID.log” # archived log format

DSMPATH=/usr/bin # dsmc command path

# try:

# /usr/sbin for Solaris

# /usr/bin for AIX

STPATH=/usr/local/bin # sendtrap command path

TMP=/tmp # temp path

export ARCHIVELOGDIR ARCHIVELOGFMT

export DSMPATH STPATH TMP

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

# ————— variables common to archival processes ———————–

ARCH_JOB_LOGS=$ARCHIVE_DIR/joblogs # job log dest

ARCH_ADSM_LOGS=$ARCHIVE_DIR/adsmlogs # adsm log dest

ARCH_COMMON_SCRIPTS=$COMMON_DIR/common_scripts # common script dest

ARCH_RETR_SCRIPTS=$ARCHIVE_DIR/recv # adsm retr script dest

FILELST=$ARCH_JOB_LOGS # file list dest

WAIT_SLEEP=15 # number of seconds to sleep

# waiting for log switch

# to finish

MAX_WAIT_COUNT=20 # maximum number of times

# to wait WAIT_SLEEP seconds

# before terminating the

# archive backup

# with a return code of 8.

# Recommend

# WAIT_SLEEP X MAX_WAIT_COUNT

# less than 1 minute.

ARCH_LOGS_TO_KEEP=15 # number of archived redo

# logs to keep in the

# ARCHIVELOGSAVEDIR directory

# after archiving to ADSM

KEEP_UNITS=count # the meaning of

# ARCH_LOGS_TO_KEEP.

# Possible values are:

# days = number of days

# to keep them.

# count = number of

# files to keep.

VERSION=prod # versions of the script:

# prod = production

# devl = development

# qlty = quality

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

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

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

USER_EXIT_1=”$ARCHIVE_DIR/scripts/usrexit1.sh” # user exit script dest

USER_EXIT_2=”$ARCHIVE_DIR/scripts/usrexit2.sh”

USER_EXIT_3=”$ARCHIVE_DIR/scripts/usrexit3.sh”

USER_EXIT_4=”$ARCHIVE_DIR/scripts/usrexit4.sh”

JDATE=`date +%y%j`

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

export EXIT_0 EXIT_4 EXIT_8

export USER_EXIT_1 USER_EXIT_2 USER_EXIT_3 USER_EXIT_4

export ARCH_JOB_LOGS ARCH_ADSM_LOGS ARCH_COMMON_SCRIPTS

export FILELST WAIT_SLEEP ARCH_LOGS_TO_KEEP KEEP_UNITS VERSION JDATE CTIME

export MAX_WAIT_COUNT

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

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

. $ARCH_COMMON_SCRIPTS/arch_$VERSION.sh # read in common functions

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

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

param_set # set parameters for function – required

#chk_dup_process # check to see if this process is still running

# required

db_status # check database status

#user_exit_1 # user exit 1

get_archnames # get archived log files to send to ADSM

switch_logfiles # alter system switch logfiles

sleep 10

#user_exit_2 # user exit 2

arch_log_list # record current active log list in joblog

df_to_adsm # archive archived log files directly to ADSM

#user_exit_3 # user exit 3

cleanup_archive_dir # remove old archive logs from save directory

#user_exit_4 # user exit 4

clean_up # clean up directorys

save_to_adsm # archive joblogs and

# filelist to ADSM

create_stats # generate ADSM statistics for this backup

exit_0 # Archive successful routine

No comments:

Post a Comment