Convert to use ksh

This commit is contained in:
2025-10-28 07:25:18 -04:00
parent ab2e15d717
commit 67050cf3a0
6 changed files with 173 additions and 144 deletions

142
rman_db.ksh Executable file
View File

@@ -0,0 +1,142 @@
#!/usr/bin/ksh
#
# RMAN DB backup with incremental Merge
# Written for HCL / Nokia
# v1.0 - James Pattinson - October 2025
#
# usage: rman_db.ksh <ORACLE_SID>
get_script_dir() {
# Portable way to get script directory for Linux and HP/UX (ksh compatible)
src="$0"
while [ -h "$src" ]; do
dir=$(cd -P $(dirname "$src") >/dev/null 2>&1 && pwd)
src=$(readlink "$src")
case $src in
/*) ;; # absolute path
*) src="$dir/$src";;
esac
done
cd -P $(dirname "$src") >/dev/null 2>&1 && pwd
}
MYDIR=$(get_script_dir)
export ORACLE_SID=$1
# . $HOME/.profile
export ORAENV_ASK=NO
export ORACLE_SID=$1
. oraenv
export ORAENV_ASK=YES
. $MYDIR/rbk_api.conf
. $MYDIR/oracle_funcs.ksh
#ORACLE_SID=$1
usage() {
echo "Usage: $0 <DBNAME>]" 1>&2
exit 1
}
if [ -z "${ORACLE_SID}" ]; then
usage
fi
#ORAENV_ASK=NO
#. oraenv
export NLS_DATE_FORMAT='mm-dd-yyyy hh24:mi:ss'
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
MOUNTPOINT=$MOUNTPOINT_PREFIX/$ORACLE_SID/data
mkdir -p $RMAN_LOG_DIR/$ORACLE_SID/
RMAN_LOG=$RMAN_LOG_DIR/$ORACLE_SID/rman_${ORACLE_SID}_DB_$(date +%d%m%y).log
# Disk space check
dusage=$(df -Ph | egrep "$MOUNTPOINT" | sed s/%//g | awk -v spaceWarn=$MV_SPACE_WARN '{ if($5 >= spaceWarn) print $0;}')
if [ "$dusage" != "" ]; then
echo "WARNING: Disk Space Alert - sending email"
echo "$dusage" | mailx -s "WARNING: Rubrik MV Disk Space Alert On $(hostname) at $(date)" $ALERT_EMAILS
else
echo "INFO: Rubrik MV Disk usage is under threshold of ${MV_SPACE_WARN}%"
fi
get_data_mv
open_mv
echo "DEBUG: numChannels=$numChannels, MOUNTPOINT=$MOUNTPOINT"
if [ $? -ne 0 ]; then
echo ERROR: Unable to open MV, aborting
exit_with_error
fi
echo Running RMAN with log to $RMAN_LOG
if [ $numChannels -eq 1 ]; then
allocate="allocate channel 'ch1' device type disk format '$MOUNTPOINT/%U';"
release="release channel ch1;"
channel0="$MOUNTPOINT"
else
allocate=""
release=""
i=0
while [ $i -lt $numChannels ]; do
allocate="$allocate allocate channel 'c$i' device type disk format '$MOUNTPOINT/c$i/%U';"
release="$release release channel c$i;"
i=$(expr $i + 1)
done
channel0="$MOUNTPOINT/c0"
fi
# Save the current time (minus one hour) to ensure we catch all archive logs
startTime=$(date +%m-%d-%Y\ %H:%M:%S -d '-1 hour')
# RMAN Part Here
###############################################################################
#cat > /tmp/rman.cmd <<EOF
# Now perform the backup and merge
rman nocatalog log $RMAN_LOG append > /dev/null <<EOF
#cat <<EOF
connect target /
set echo on;
configure retention policy to recovery window of 1 days;
run {
set controlfile autobackup format for device type disk to '$channel0/cf_%F';
$allocate
backup incremental level 1 for recover of copy with tag 'rubrik_snap' database;
recover copy of database with tag 'rubrik_snap';
backup as copy current controlfile;
backup archivelog from time '$startTime' tag 'rubrik_snap_logs';
$release
}
allocate channel for maintenance device type disk;
crosscheck backup;
crosscheck copy;
delete noprompt obsolete device type disk;
delete noprompt backup of archivelog all completed before 'sysdate-2' tag rubrik_snap_logs;
release channel;
EOF
###############################################################################
rmanStatus=$?
if [ $rmanStatus -ne 0 ]; then
echo "WARNING: RMAN DB backup exited with Non-zero status $rmanStatus. Emailing log"
cat $RMAN_LOG | mailx -s "RMAN Log backup Failed on ${HOST} for ${ORACLE_SID}" $ALERT_EMAILS
elif [ $EMAIL_SUCCESS -eq 1 ]; then
echo "SUCCESS: RMAN DB backup exited with zero status"
echo "RMAN job finished with Zero status. Note that this does not guarantee the contents of the backup." | mailx -s "SUCCESS: RMAN DB backup exited with zero status on ${HOST} for ${ORACLE_SID}" $ALERT_EMAILS
fi
# Change permission of backup files to enable alternate host restore
find $MOUNTPOINT -type f -exec chmod 644 {} + 2>/dev/null
close_mv