143 lines
4.0 KiB
Bash
Executable File
143 lines
4.0 KiB
Bash
Executable File
#!/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() {
|
|
src="$0"
|
|
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd)
|
|
echo "$dir"
|
|
}
|
|
MYDIR=$(get_script_dir)
|
|
|
|
export ORACLE_SID=$1
|
|
|
|
# . $HOME/.profile
|
|
|
|
export ORAENV_ASK=NO
|
|
export ORACLE_SID=$1
|
|
|
|
. oraenv
|
|
|
|
export ORAENV_ASK=YES
|
|
|
|
. $MYDIR/rubrik.conf
|
|
. $MYDIR/oracle_funcs.ksh
|
|
|
|
#ORACLE_SID=$1
|
|
|
|
usage() {
|
|
echo "Usage: $0 <DBNAME>]" 1>&2
|
|
exit 1
|
|
}
|
|
|
|
if [ -z "${ORACLE_SID}" ]; then
|
|
usage
|
|
fi
|
|
|
|
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
|
|
|
|
# Default RMAN channels per mount if not set
|
|
RMAN_CHANNELS_PER_MOUNT=${RMAN_CHANNELS_PER_MOUNT:-1}
|
|
|
|
total_channels=$(expr $numChannels \* $RMAN_CHANNELS_PER_MOUNT)
|
|
|
|
if [ $total_channels -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
|
|
j=0
|
|
while [ $j -lt $RMAN_CHANNELS_PER_MOUNT ]; do
|
|
suffix=$(echo $j | tr '0123456789' 'abcdefghijklmnopqrstuvwxyz')
|
|
allocate="$allocate allocate channel 'c${i}${suffix}' device type disk format '$MOUNTPOINT/c$i/%U';"
|
|
release="$release release channel c${i}${suffix};"
|
|
j=$(expr $j + 1)
|
|
done
|
|
i=$(expr $i + 1)
|
|
done
|
|
channel0="$MOUNTPOINT/c0"
|
|
fi
|
|
|
|
|
|
# Save the current time (minus one hour) to ensure we catch all archive logs
|
|
startTime=$(perl -e 'use POSIX qw(strftime); $time = time() - 3600; print strftime("%m-%d-%Y %H:%M:%S", localtime($time))')
|
|
|
|
# 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 {
|
|
CONFIGURE BACKUP OPTIMIZATION OFF;
|
|
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 |