#!/bin/ksh -p
# Program Notes
# hot_backup.ksh
(version 2 -- not named as such for backward compatibility with osb_menu.sh)
#
# Development
script for new online hot backup script to replace hot_backup.ksh script i
# currently in
use.
#
# Usage: hot_backup_v30.ksh xx
#
# where
"xx" is [ pr, t2, d1, ... ]
# verify directory
paths (see below) for $dest $dest_prev $dest_files $BACKUP_SOURCE before
# implementing
on a new environment.
#
# verify existence
of $ORACLE_HOME/pfcs"xx".env file before implementing this script on
# a new
environment
##################################################################################################
[ "${DEBUG}" = "TRUE" ] &&
set -x
export xx=$1
cd /home/orapf"$xx"
. .profile
PATH=$PATH:/usr/contrib/bin
cd /home/orapf"$xx"/osbmenu
export SID=pfcs"$xx"
export
ORACLE_HOME=/mnt/pfcs/"${SID}"/"${SID}"db/8.1.7
export
DBADMIN=/mnt/pfcs/"${SID}"/"${SID}"db/8.1.7/admin/pfcs"$xx"
. ${ORACLE_HOME}/pfcs"$xx".env
export U='unisys.com'
export USDA='stl.rural.usda.gov'
export NotifyList="gs1114@$USDA lb1088@$USDA
dm1175@$USDA Mitchell.Clem@$U"
export PagerList="3144245868@myairmail.com
8007208398.0803232@pagenet.net"
#export PagerList="gs1114@$USDA"
#export NotifyList="gs1114@$USDA"
##################################################################################################
# Fail Safe to make sure ORACLE_SID is set correctly
(overrides ${ORACLE_HOME}/pfcs"$xx".env).
#
export ORACLE_SID=pfcs"$xx"
##################################################################################################
##################################################################################################
# From the first hot_backup.ksh script for backward
compatibility with osb_menu.sh
# osb_menu.sh looks for $LOG_FILE at the end of the run
to confirm the backup was
# completed. Note:
a more detailed method should be implemented to verify complete.
# osb_menu.sh should be revised to make backup checking
more detailed as well.
export TIMESTAMP=`date +%y%m%d_%H%M%S`
export DATESTAMP=`date +%y%m%d`
#
SOURCE=/mnt/pfcs/pfcs"$xx"/pfcs"$xx"data/ -GLS 04/01/23 obsolete. Source pulled from Ora DD now.
# DEST=/mnt/pfcs/pfcs"$xx"/HOTBACKUP/backup
-GLS 04/01/23 obsolete. Uses $dest and
$dest_prev now.
export BACKUP_SOURCE=/home/orapf"$xx"/osbmenu
export LOG_SOURCE=${BACKUP_SOURCE}/log
export
RUNNING_FILE=${LOG_SOURCE}/RUNNING_${ORACLE_SID}_${TIMESTAMP}.txt
export
LOG_FILE=${LOG_SOURCE}/LOG_${ORACLE_SID}_${TIMESTAMP}.txt
echo "${TIMESTAMP}- Starting Backup"
>$RUNNING_FILE
# End code from the first hot_backup.ksh script for
backward compatibility
##################################################################################################
date '+%y%m%d' | read ext1
export ext1
##################################################################################################
# $dest and $dest_prev are chosen for backward
compatibility with first hot_backup.ksh disk locs
# $dest_files is added and is an archive of the scripts
used to actually carry out the os commands
export
dest=/mnt/pfcs/pfcs"$xx"/HOTBACKUP/backup/
export
dest_prev=/mnt/pfcs/pfcs"$xx"/HOTBACKUP/backup2/
export
dest_files=/mnt/pfcs/pfcs"$xx"/HOTBACKUP/tablespace_copy_scripts/
export
DBA_LOG=/home/orapf"$xx"/osbmenu/log/dba_backup_log.$ext1
# End code for backward compatibility with backup disk
locations
##################################################################################################
# make our locs if needed
if [ ! -d
${dest} ]
then
mkdir ${dest}
chmod 0777
${dest}
fi
if [ ! -d
${dest_prev} ]
then
mkdir
${dest_prev}
chmod 0777
${dest_prev}
fi
if [ ! -d
${dest_files} ]
then
mkdir ${dest_files}
chmod 0777
${dest_files}
fi
# export OPER_LOG=${LOG_SOURCE}/log_`date
+%y%m%d%H%M`.log -GLS 04/01/23 Was
never used.
#if [ -r /mnt/pfcs/pfcs"$xx"/HOTBACKUP/backup/*
]
#then
#mv /mnt/pfcs/pfcs"$xx"/HOTBACKUP/backup/* /mnt/pfcs/pfcs"$xx"/HOTBACKUP/backup2/.
#fi
TMPFILE=/tmp/$$${RANDOM}.tmp
export TMPFILE
echo $0 starting execution `date` >> $RUNNING_FILE
check_file_status_v32.ksh $ORACLE_HOME $ORACLE_SID $ext1
$TMPFILE $RUNNING_FILE $LOG_FILE $xx
if [ -r "${dest}"control.bak ]
then
mv "${dest}"control.bak
"${dest_prev}"control.bak."$ext1"
fi
# rm -f ${dest}/control.bak - GLS 04/01/23 Obsolete. Doing a mv now instead of rm -f to retain
previous.
rm ${TMPFILE}
############################################################################################################
# special version of $dest for use in the controlfile
binary backup (needs quotes around value)
export
dest_for_controlfile_backup="'/mnt/pfcs/pfcs"$xx"/HOTBACKUP/backup/control.bak'"
#ps -ef | grep 'gzip -c' | wc -l | read
parallel_write_count2
#export pwc2=$parallel_write_count2
#echo 'parallel_write_count2='$pwc2 >> $5
#echo 'parallel_write_count2='$pwc2
#while [ $pwc2 -gt 1 ]
#do
#ps -ef | grep 'gzip -c' | wc -l | read parallel_write_count2
#ps -ef | grep 'gzip -c' | wc -l
#export pwc2=$parallel_write_count2
#done
#ps -ef | grep 'gzip -c' | wc -l
echo "alter
database backup controlfile to ${dest_for_controlfile_backup};
quit
" | sqlplus -s "/ as sysdba" | sed
'/^$/d' | tr -d '\012' | tr -d '\015' | read bcstat2
echo $bcstat2
| sed 's/\.//' | sed 's/ //' | read bcstat
echo $bcstat
>> $RUNNING_FILE
if [ $bcstat
= 'Databasealtered' ]
then
date >>
$RUNNING_FILE
echo 'alter
system backup controlfile executed successfully' >> $RUNNING_FILE
echo 'alter
system backup controlfile executed successfully' >> $DBA_LOG
fi
echo "alter
database backup controlfile to trace;
quit
" | sqlplus -s "/ as sysdba" | sed
'/^$/d' | tr -d '\012' | tr -d '\015' | read bctstat2
echo
$bctstat2 | sed 's/\.//' | sed 's/ //' | read bctstat
echo $bctstat
>> $RUNNING_FILE
if [ $bctstat
= 'Databasealtered' ]
then
date >>
$RUNNING_FILE
echo 'alter system backup controlfile to
trace executed successfully' >> $RUNNING_FILE
echo 'alter
system backup controlfile to trace executed successfully' >> $DBA_LOG
fi
echo "alter
system archive log current;
quit
" | sqlplus -s "/ as sysdba" | sed
'/^$/d' | tr -d '\012' | tr -d '\015' | read alcstat2
echo $alcstat2
| sed 's/\.//' | sed 's/ //' | read alcstat
echo $alcstat
>> $RUNNING_FILE
if [ $alcstat
= 'Systemaltered' ]
then
date >>
$RUNNING_FILE
echo 'alter
system archive log current executed successfully' >> $RUNNING_FILE
echo 'alter
system archive log current executed successfully' >> $DBA_LOG
fi
echo ' ' >> $RUNNING_FILE
echo 'Status of All Datafiles from v$backup follows:'
>> $RUNNING_FILE
echo ' ' >> $RUNNING_FILE
echo "set
linesize 200 pagesize 0
column file_name format a60
select distinct b.status, a.tablespace_name
from dba_data_files a, v\$backup b
where a.file_id = b.file#
order by a.tablespace_name;
quit
" | sqlplus -s "/ as sysdba" >>
$RUNNING_FILE
date '+%Y-%m-%d' | read trc_dt
egrep -l "CONTROLFILE|$trc_dt"
"$DBADMIN"/udump/*.trc | read crt_ctl_scr_nm
touch
"${dest}"create_controlfile_script."$ext1"
cp -p $crt_ctl_scr_nm
"${dest}"create_controlfile_script."$ext1"
###########################################################################################################
echo $0 done with backup `date` >> $RUNNING_FILE
TIMESTAMP=`date +%y%m%d_%H%M%S`
echo "${TIMESTAMP}- Ending Backup"
>>$RUNNING_FILE
mv $RUNNING_FILE $LOG_FILE
############################################################################################################
# Pruning phase to remove previous aged out hot backups.
# Pruning phase to remove old trace files as well
if [ -r "$dest_prev"*.gz ]
then
find "$dest_prev"*.gz \( -type d ! -name .
-prune \) -o \( -type f -mtime +0 ! -name ".*" \) -exec rm {} \;
fi
if [ -r "$DBADMIN"/udump/*.trc ]
then
find "$DBADMIN"/udump/*.trc \( -type d ! -name
. -prune \) -o \( -type f -mtime +7 ! -name ".*" \) -exec rm {} \;
fi
if [ -r
"${LOG_SOURCE}"/LOG_"${ORACLE_SID}"_* ]
then
find
"${LOG_SOURCE}"/LOG_"${ORACLE_SID}"_* \( -type d ! -name .
-prune \) -o \( -type f -mtime +7 ! -name ".*" \) -exec rm {} \;
fi
#
############################################################################################################
more $LOG_FILE | grep 'NOT ACTIVE' | wc -l | read filect1
more $LOG_FILE | grep 'rows selected' | cut -f1 -d' ' |
read filect2
more $LOG_FILE | grep 'successfully' | wc -l | read
pbactions
if [ $filect1 -ne $filect2 ] || [ $pbactions -ne 3 ]
then
echo 'sending warning message' >> $LOG_FILE
mailx -m -s "Warning: DBA Verify Nightly Hot Backup - Review Log
" $NotifyList $PagerList < $DBA_LOG
else
echo 'sending completion message' >> $LOG_FILE
mailx -m -s "Hot Backup Completed Successfully"
$NotifyList < $DBA_LOG
fi
exit
exit