Compare commits

..

3 Commits

Author SHA1 Message Date
04d946aa00 Get env from oratab not oraenv 2025-11-11 09:06:47 -05:00
bd7d5da70e HP/UX changes after site testing 2025-11-11 06:02:54 -05:00
c2ef3e05e3 Minor tweaks 2025-11-06 06:15:44 -05:00
7 changed files with 172 additions and 83 deletions

2
.gitignore vendored
View File

@@ -23,3 +23,5 @@ rubrik.conf
# Other common ignores
*.swp
*.swo
releases/

View File

@@ -5,13 +5,26 @@
# v1.1 - James Pattinson - October 2025
#
# usage: list_mv.ksh
_SCRIPT_="$0"
get_script_dir() {
src="$0"
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd)
echo "$dir"
script="$1"
case "$script" in
/*) abs_path="$script" ;;
*) abs_path="$PWD/$script" ;;
esac
while [ -L "$abs_path" ]; do
link=$(readlink "$abs_path")
case "$link" in
/*) abs_path="$link" ;;
*) abs_path="$(dirname "$abs_path")/$link" ;;
esac
done
script_dir=$(dirname "$abs_path")
cd "$script_dir" 2>/dev/null && pwd
}
MYDIR=$(get_script_dir)
MYDIR=$(get_script_dir "$_SCRIPT_")
. $MYDIR/rubrik.conf
. $MYDIR/oracle_funcs.ksh
@@ -45,3 +58,4 @@ awk '
' /tmp/rbkresponse.$$
cleanup

View File

@@ -2,7 +2,7 @@
#
# Oracle shell script support functions
# Written for HCL / Nokia
# v1.0 - James Pattinson - October 2025
# v1.0 - James Pattinson - November 2025
nowait=0
@@ -13,11 +13,18 @@ tabwidth=25
# Portable short hostname function
get_short_hostname() {
# Check OS type first - HP-UX hostname doesn't support -s
os_type=$(uname -s)
if [ "$os_type" = "HP-UX" ]; then
hostname | awk -F. '{print $1}'
else
# Try -s flag on other systems
if hostname -s >/dev/null 2>&1; then
hostname -s
else
hostname | awk -F. '{print $1}'
fi
fi
}
HOST=$(get_short_hostname)
@@ -73,7 +80,8 @@ exit_with_error() {
check_http_error() {
# All good responses start with a 2
if [ ${http_response:0:1} != "2" ]; then
first_char=$(echo "$http_response" | cut -c1)
if [ "$first_char" != "2" ]; then
echo FATAL: HTTP error from API call: $http_response. The server responded with:
cat /tmp/rbkresponse.$$ ; echo ; exit_with_error
fi
@@ -210,7 +218,7 @@ get_mv() {
mvId=$(awk '{match($0, /ManagedVolume:::[a-z0-9-]*/); if (RSTART > 0) {id=substr($0, RSTART, RLENGTH); sub(/"$/, "", id); print id}}' /tmp/rbkresponse.$$)
numChannels=$(awk '{match($0, /"numChannels":[ ]*[0-9]+/); if (RSTART > 0) {val=substr($0, RSTART, RLENGTH); sub(/.*:[ ]*/, "", val); print val}}' /tmp/rbkresponse.$$)
if [[ $mvId == "" ]]; then
if [ -z "$mvId" ]; then
echo ERROR: MV with name $mv_name was not found
exit_with_error
fi
@@ -219,7 +227,7 @@ get_mv() {
get_data_mv() {
mv_name=${HOST}_${ORACLE_SID}_data
mv_name=${HOST}_${ORACLE_SID}_Data
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get
@@ -227,7 +235,7 @@ get_data_mv() {
mvId=$(awk '{match($0, /ManagedVolume:::[a-z0-9-]*/); if (RSTART > 0) {id=substr($0, RSTART, RLENGTH); sub(/"$/, "", id); print id}}' /tmp/rbkresponse.$$)
numChannels=$(awk '{match($0, /"numChannels":[ ]*[0-9]+/); if (RSTART > 0) {val=substr($0, RSTART, RLENGTH); sub(/.*:[ ]*/, "", val); print val}}' /tmp/rbkresponse.$$)
if [[ $mvId == "" ]]; then
if [ -z "$mvId" ]; then
echo ERROR: MV with name $mv_name was not found
exit_with_error
fi
@@ -238,16 +246,16 @@ get_log_mv() {
# Look for a log volume. If not present, return the data volume
mv_name=${HOST}_${ORACLE_SID}_logs
mv_name=${HOST}_${ORACLE_SID}_Log
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get
logMvId=$(awk '{match($0, /ManagedVolume:::[a-z0-9-]*/); if (RSTART > 0) {id=substr($0, RSTART, RLENGTH); sub(/"$/, "", id); print id}}' /tmp/rbkresponse.$$)
if [[ $logMvId == "" ]]; then
if [ -z "$logMvId" ]; then
echo "INFO: Log volume ($mv_name) not found. Logs will be written to DB volume"
logMvPresent=0
mv_name=${HOST}_${ORACLE_SID}_data
mv_name=${HOST}_${ORACLE_SID}_Data
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get
@@ -255,7 +263,7 @@ get_log_mv() {
mvId=$(awk '{match($0, /ManagedVolume:::[a-z0-9-]*/); if (RSTART > 0) {id=substr($0, RSTART, RLENGTH); sub(/"$/, "", id); print id}}' /tmp/rbkresponse.$$)
numChannels=$(awk '{match($0, /"numChannels":[ ]*[0-9]+/); if (RSTART > 0) {val=substr($0, RSTART, RLENGTH); sub(/.*:[ ]*/, "", val); print val}}' /tmp/rbkresponse.$$)
if [[ $mvId == "" ]]; then
if [ -z "$mvId" ]; then
echo ERROR: MV with name $mv_name was not found
exit_with_error
fi
@@ -268,6 +276,16 @@ get_log_mv() {
}
set_oracle_env() {
ORACLE_HOME=$(awk -F: '$1 == "'$1'" {print $2}' /etc/oratab)
PATH=$PATH:$ORACLE_HOME/bin
ORACLE_SID=$1
if [ -z "$ORACLE_HOME" ]; then
echo "ERROR: SID $1 not found in /etc/oratab"
exit_with_error
fi
}
open_mv() {
PIDFILE=/tmp/mvLock_${mv_name}.pid

View File

@@ -2,32 +2,38 @@
#
# RMAN DB backup with incremental Merge
# Written for HCL / Nokia
# v1.0 - James Pattinson - October 2025
# v1.0 - James Pattinson - November 2025
#
# usage: rman_db.ksh <ORACLE_SID>
_SCRIPT_="$0"
get_script_dir() {
src="$0"
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd)
echo "$dir"
script="$1"
case "$script" in
/*) abs_path="$script" ;;
*) abs_path="$PWD/$script" ;;
esac
while [ -L "$abs_path" ]; do
link=$(readlink "$abs_path")
case "$link" in
/*) abs_path="$link" ;;
*) abs_path="$(dirname "$abs_path")/$link" ;;
esac
done
script_dir=$(dirname "$abs_path")
cd "$script_dir" 2>/dev/null && 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=$(get_script_dir "$_SCRIPT_")
. $MYDIR/rubrik.conf
. $MYDIR/oracle_funcs.ksh
#ORACLE_SID=$1
set_oracle_env $1
export NLS_DATE_FORMAT='mm-dd-yyyy hh24:mi:ss'
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
usage() {
echo "Usage: $0 <DBNAME>]" 1>&2
@@ -38,16 +44,13 @@ 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;}')
dusage=$(df -Pk | grep -E "$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
@@ -138,6 +141,6 @@ elif [ $EMAIL_SUCCESS -eq 1 ]; then
fi
# Change permission of backup files to enable alternate host restore
find $MOUNTPOINT -type f -exec chmod 644 {} + 2>/dev/null
find $MOUNTPOINT -type f -exec chmod 644 {} \; 2>/dev/null
close_mv

View File

@@ -2,30 +2,39 @@
#
# RMAN Log backup
# Written for HCL / Nokia
# v1.1 - James Pattinson - October 2025
# v1.1 - James Pattinson - November 2025
#
# usage: rman_logs.ksh <ORACLE_SID>
_SCRIPT_="$0"
get_script_dir() {
src="$0"
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd)
echo "$dir"
script="$1"
case "$script" in
/*) abs_path="$script" ;;
*) abs_path="$PWD/$script" ;;
esac
while [ -L "$abs_path" ]; do
link=$(readlink "$abs_path")
case "$link" in
/*) abs_path="$link" ;;
*) abs_path="$(dirname "$abs_path")/$link" ;;
esac
done
script_dir=$(dirname "$abs_path")
cd "$script_dir" 2>/dev/null && 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=$(get_script_dir "$_SCRIPT_")
. $MYDIR/rubrik.conf
. $MYDIR/oracle_funcs.ksh
set_oracle_env $1
export NLS_DATE_FORMAT='mm-dd-yyyy hh24:mi:ss'
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
usage() {
echo "Usage: $0 <DBNAME>]" 1>&2
exit 1
@@ -35,24 +44,26 @@ if [ -z "${ORACLE_SID}" ]; then
usage
fi
export NLS_DATE_FORMAT='mm-dd-yyyy hh24:mi:ss'
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
mkdir -p $RMAN_LOG_DIR/$ORACLE_SID/
RMAN_LOG=$RMAN_LOG_DIR/$ORACLE_SID/rman_${ORACLE_SID}_LOG_$(date +%d%m%y).log
get_log_mv
open_mv
if [ -z "$numChannels" ]; then
echo "WARNING: numChannels not found, setting to 1"
numChannels=1
fi
if [ $? -ne 0 ]; then
echo ERROR: Unable to open MV, aborting
exit_with_error
fi
MOUNTPOINT=$MOUNTPOINT_PREFIX/$ORACLE_SID/logs
MOUNTPOINT=$MOUNTPOINT_PREFIX/$ORACLE_SID/log
# Disk space check
dusage=$(df -Ph | egrep "$MOUNTPOINT" | sed s/%//g | awk -v spaceWarn=$MV_SPACE_WARN '{ if($5 >= spaceWarn) print $0;}')
dusage=$(df -Pk | grep -E "$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
@@ -120,7 +131,7 @@ elif [ $EMAIL_SUCCESS -eq 1 ]; then
fi
# Change permission of backup files to enable alternate host restore
find $MOUNTPOINT -type f -exec chmod 644 {} + 2>/dev/null
find $MOUNTPOINT -type f -exec chmod 644 {} \; 2>/dev/null
close_mv

View File

@@ -28,4 +28,4 @@ RMAN_LOG_DIR=/tmp/rubrik/rman
# List of email addresses to send failure alerts to
ALERT_EMAILS=root,oracle
# Set to 1 to enable email alert on success also
EMAIL_SUCCESS=1
EMAIL_SUCCESS=0

View File

@@ -10,23 +10,45 @@
# -v Volume to operate on, logs or data
# -o Operation to perform - open or close the MV
_SCRIPT_="$0"
get_script_dir() {
src="$0"
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd)
echo "$dir"
script="$1"
case "$script" in
/*) abs_path="$script" ;;
*) abs_path="$PWD/$script" ;;
esac
while [ -L "$abs_path" ]; do
link=$(readlink "$abs_path")
case "$link" in
/*) abs_path="$link" ;;
*) abs_path="$(dirname "$abs_path")/$link" ;;
esac
done
script_dir=$(dirname "$abs_path")
cd "$script_dir" 2>/dev/null && pwd
}
MYDIR=$(get_script_dir)
. $MYDIR/rbk_api.conf
MYDIR=$(get_script_dir "$_SCRIPT_")
. $MYDIR/rubrik.conf
. $MYDIR/oracle_funcs.ksh
usage() {
echo "Usage: $0 -d <DBNAME> -v <logs|data> -o <open|close>" 1>&2
echo "Usage: $0 -d <DBNAME> -v <logs|data> -o <open|close>"
echo " $0 -n <MV_NAME> -o <open|close>"
echo " -d Oracle DBNAME"
echo " -v Volume to operate on, logs or data"
echo " -o Operation to perform - open or close the MV"
echo " -n Specify MV name directly (use only with -o)"
exit 1
}
force=0
while getopts "d:v:o:" o; do
force=0
MVNAME=""
while getopts "d:v:o:n:" o; do
case "${o}" in
d)
DBNAME=${OPTARG}
@@ -37,6 +59,9 @@ while getopts "d:v:o:" o; do
o)
OPCODE=${OPTARG}
;;
n)
MVNAME=${OPTARG}
;;
*)
usage
;;
@@ -44,20 +69,36 @@ while getopts "d:v:o:" o; do
done
shift $((OPTIND-1))
if [ -z "${DBNAME}" ] || [ -z "${VOLUME}" ] || [ -z "${OPCODE}" ]; then
# Validate options
if [ -n "$MVNAME" ]; then
# Direct MV name mode: require -n and -o only
if [ -z "$OPCODE" ]; then
usage
fi
mv_name="$MVNAME"
elif [ -n "$DBNAME" ] && [ -n "$VOLUME" ] && [ -n "$OPCODE" ]; then
# Standard mode: require -d, -v, -o
mv_name=$(get_short_hostname)_${DBNAME}_${VOLUME}
else
usage
fi
# Script starts here
get_short_hostname() {
# Check OS type first - HP-UX hostname doesn't support -s
os_type=$(uname -s)
if [ "$os_type" = "HP-UX" ]; then
hostname | awk -F. '{print $1}'
else
# Try -s flag on other systems
if hostname -s >/dev/null 2>&1; then
hostname -s
else
hostname | awk -F. '{print $1}'
fi
fi
}
mv_name=$(get_short_hostname)_${DBNAME}_${VOLUME}
get_mv
case $OPCODE in