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

48
list_mv.ksh Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/ksh
#
# List MVs using API call to RSC, for diagnostic purposes
# Written for HCL / Nokia
# v1.1 - James Pattinson - October 2025
#
# usage: list_mv.ksh
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)
. $MYDIR/rbk_api.conf
. $MYDIR/oracle_funcs.ksh
# Script starts here
echo "Service account in use is $ID"
echo "Managed Volumes"
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume"
rest_api_get
awk '{
pos = 1
while (match(substr($0, pos), /"name":"[^"]*"/)) {
name = substr($0, pos + RSTART + 7, RLENGTH - 8)
# Remove any trailing quote if present
sub(/"$/, "", name)
print name
pos += RSTART + RLENGTH - 1
}
}' /tmp/rbkresponse.$$
cleanup

View File

@@ -1,35 +0,0 @@
#!/bin/bash
#
# List MVs using API call to RSC, for diagnostic purposes
# Written for HCL / Nokia
# v1.1 - James Pattinson - October 2025
#
# usage: list_mv.sh
get_script_dir() {
# Portable way to get script directory for Linux and HP/UX
local src="$0"
while [ -h "$src" ]; do
dir="$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd)"
src="$(readlink "$src")"
[[ $src != /* ]] && src="$dir/$src"
done
cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd
}
MYDIR="$(get_script_dir)"
source $MYDIR/rbk_api.conf
source $MYDIR/oracle_funcs.sh
# Script starts here
echo Service account in use is $ID
echo "Managed Volumes"
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume"
rest_api_get
grep -o '"name":"[^"]*"' /tmp/rbkresponse.$$ | cut -d'"' -f4
cleanup

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/ksh
#
# Oracle shell script support functions
# Written for HCL / Nokia
@@ -50,12 +50,14 @@ echo "`$DATE` -$$-: CALLED $0 $@" >> $LOGFILE
trap ctrl_c INT
function ctrl_c () {
ctrl_c() {
echo "`$DATE` -$$-: TRAPPED CTRL-C - EXITING" >> $LOGFILE
exit_with_error
}
function ctrl_c_inhibit () {
ctrl_c_inhibit() {
echo "`$DATE` -$$-: TRAPPED CTRL-C - CONTINUING" >> $LOGFILE
}
@@ -126,20 +128,17 @@ check_get_token () {
get_token() {
trap '' INT
echo "`$DATE` -$$-: AUTH USER $ID" >> $LOGFILE
MYENDPOINT="https://$RUBRIK_IP/api/v1/service_account/session"
MYPAYLOAD="{\"serviceAccountId\":\"$ID\",\"secret\":\"$SECRET\"}"
MYPAYLOAD='{"serviceAccountId":"'$ID'","secret":"'$SECRET'"}'
http_response=$(curl -s -k -o /tmp/rbkresponse.$$ -w "%{http_code}" -X POST $MYENDPOINT -H "accept: application/json" -H "Content-Type: application/json" -d $MYPAYLOAD)
http_response=$(curl -s -k -o /tmp/rbkresponse.$$ -w "%{http_code}" -X POST $MYENDPOINT -H "accept: application/json" -H "Content-Type: application/json" -d "$MYPAYLOAD")
check_http_error
AUTH_TOKEN=$(grep -o '"token":"[^"]*"' /tmp/rbkresponse.$$ | cut -d'"' -f4)
SESSION=$(egrep '"sessionId"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}' | sed 's/\"//g')
EXPIRATION=$(egrep '"expirationTime"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}' | sed 's/\"//g' | sed 's/.000Z//;s/T/Z/')
AUTH_TOKEN=$(cat /tmp/rbkresponse.$$ | awk '{match($0, /"token":"[^"]*"/); if (RSTART > 0) {print substr($0, RSTART+9, RLENGTH-10);}}')
echo "`$DATE` -$$-: AUTH SESSION $SESSION" >> $LOGFILE
trap ctrl_c INT
}
# HTTP GET: Given $ENDPOINT write output to file
@@ -214,8 +213,8 @@ get_mv () {
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get
mvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
numChannels=$(egrep '"numChannels"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}')
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
echo ERROR: MV with name $mv_name was not found
@@ -231,8 +230,8 @@ get_data_mv () {
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get
mvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
numChannels=$(egrep '"numChannels"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}')
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
echo ERROR: MV with name $mv_name was not found
@@ -245,11 +244,11 @@ get_log_mv () {
# Look for a log volume. If not present, return the data volume
mv_name=${HOST}_${ORACLE_SID}_log
mv_name=${HOST}_${ORACLE_SID}_logs
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get
logMvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
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
echo "INFO: Log volume ($mv_name) not found. Logs will be written to DB volume"
@@ -259,16 +258,16 @@ get_log_mv () {
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get
mvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
numChannels=$(egrep '"numChannels"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}')
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
echo ERROR: MV with name $mv_name was not found
exit_with_error
fi
else
mvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
numChannels=$(egrep '"numChannels"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}')
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.$$)
logMvPresent=1
echo "INFO: Log volume ($mv_name) exists with $numChannels channels"
fi

View File

@@ -1,26 +1,29 @@
#!/bin/bash
#!/usr/bin/ksh
#
# RMAN DB backup with incremental Merge
# Written for HCL / Nokia
# v1.0 - James Pattinson - October 2025
#
# usage: rman_db.sh <ORACLE_SID>
# usage: rman_db.ksh <ORACLE_SID>
get_script_dir() {
# Portable way to get script directory for Linux and HP/UX
local src="$0"
# 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")"
[[ $src != /* ]] && src="$dir/$src"
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
cd -P $(dirname "$src") >/dev/null 2>&1 && pwd
}
MYDIR="$(get_script_dir)"
MYDIR=$(get_script_dir)
export ORACLE_SID=$1
. $HOME/.profile
# . $HOME/.profile
export ORAENV_ASK=NO
export ORACLE_SID=$1
@@ -29,12 +32,15 @@ export ORACLE_SID=$1
export ORAENV_ASK=YES
source $MYDIR/rbk_api.conf
source $MYDIR/oracle_funcs.sh
. $MYDIR/rbk_api.conf
. $MYDIR/oracle_funcs.ksh
#ORACLE_SID=$1
usage() { echo "Usage: $0 <DBNAME>]" 1>&2; exit 1; }
usage() {
echo "Usage: $0 <DBNAME>]" 1>&2
exit 1
}
if [ -z "${ORACLE_SID}" ]; then
usage
@@ -46,7 +52,7 @@ fi
export NLS_DATE_FORMAT='mm-dd-yyyy hh24:mi:ss'
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
MOUNTPOINT=$MOUNTPOINT_PREFIX$ORACLE_SID
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
@@ -63,6 +69,8 @@ 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
@@ -71,18 +79,20 @@ fi
echo Running RMAN with log to $RMAN_LOG
if [[ $numChannels -eq 1 ]]; then
if [ $numChannels -eq 1 ]; then
allocate="allocate channel 'ch1' device type disk format '$MOUNTPOINT/%U';"
release="release channel ch1;"
channel0="$MOUNTPOINT"
else
for i in $(seq 0 $(($numChannels - 1))); do
allocate+="allocate channel 'c$i' device type disk format '$MOUNTPOINT/c$i/%U';"
release+="release channel c$i;"
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
@@ -94,6 +104,7 @@ startTime=$(date +%m-%d-%Y\ %H:%M:%S -d '-1 hour')
# 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;
@@ -110,7 +121,7 @@ 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-3' tag rubrik_snap_logs;
delete noprompt backup of archivelog all completed before 'sysdate-2' tag rubrik_snap_logs;
release channel;
EOF
###############################################################################

View File

@@ -1,25 +1,28 @@
#!/bin/bash
#!/usr/bin/ksh
#
# RMAN Log backup
# Written for HCL / Nokia
# v1.1 - James Pattinson - October 2025
#
# usage: rman_logs.sh <ORACLE_SID>
# usage: rman_logs.ksh <ORACLE_SID>
get_script_dir() {
# Portable way to get script directory for Linux and HP/UX
local src="$0"
# 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")"
[[ $src != /* ]] && src="$dir/$src"
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
cd -P $(dirname "$src") >/dev/null 2>&1 && pwd
}
MYDIR="$(get_script_dir)"
MYDIR=$(get_script_dir)
export ORACLE_SID=$1
. $HOME/.profile
#. $HOME/.profile
export ORAENV_ASK=NO
export ORACLE_SID=$1
@@ -28,12 +31,15 @@ export ORACLE_SID=$1
export ORAENV_ASK=YES
source $MYDIR/rbk_api.conf
source $MYDIR/oracle_funcs.sh
. $MYDIR/rbk_api.conf
. $MYDIR/oracle_funcs.ksh
#ORACLE_SID=$1
usage() { echo "Usage: $0 <DBNAME>]" 1>&2; exit 1; }
usage() {
echo "Usage: $0 <DBNAME>]" 1>&2
exit 1
}
if [ -z "${ORACLE_SID}" ]; then
usage
@@ -56,11 +62,7 @@ if [ $? -ne 0 ]; then
exit_with_error
fi
if [[ $logMvPresent -eq 1 ]] && [[ $numChannels -eq 1 ]] ; then
MOUNTPOINT=$MOUNTPOINT_PREFIX${ORACLE_SID}_log
else
MOUNTPOINT=$MOUNTPOINT_PREFIX$ORACLE_SID
fi
MOUNTPOINT=$MOUNTPOINT_PREFIX/$ORACLE_SID/logs
# Disk space check
dusage=$(df -Ph | egrep "$MOUNTPOINT" | sed s/%//g | awk -v spaceWarn=$MV_SPACE_WARN '{ if($5 >= spaceWarn) print $0;}')
@@ -73,19 +75,16 @@ 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
for i in $(seq 0 $(($numChannels - 1))); do
allocate+="allocate channel 'c$i' device type disk format '$MOUNTPOINT/log_c$i/%U';"
release+="release channel c$i;"
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/log_c0"
channel0="$MOUNTPOINT/c0"
fi
# RMAN Part Here
###############################################################################
@@ -97,11 +96,11 @@ crosscheck backup;
run {
set controlfile autobackup format for device type disk to '$channel0/cf_%F';
$allocate
backup archivelog all not backed up 1 times tag 'RUBRIK_LOGS';
backup archivelog all not backed up 1 times tag 'rubrik_pit_logs';
$release
}
allocate channel for maintenance device type disk;
delete noprompt backup of archivelog all completed before 'sysdate-3' tag RUBRIK_LOGS;
delete noprompt backup of archivelog all completed before 'sysdate-2' tag rubrik_pit_logs;
release channel;
EOF
###############################################################################
@@ -121,7 +120,8 @@ find $MOUNTPOINT -type f -exec chmod 644 {} + 2>/dev/null
close_mv
if [[ $HOSTLOGRET -gt 0 ]]; then
if [ $HOSTLOGRET -gt 0 ]; then
echo "Starting post-backup RMAN log purge"

View File

@@ -1,30 +1,36 @@
#!/bin/bash
#!/usr/bin/ksh
#
# Open and Close MV using API call to CDM
# Written for AvonHCL / Nokia
# v1.0 - James Pattinson - October 2025
#
# usage: rubrik_mv_op.sh -d <DBNAME> -v <logs|data> -o <open|close>
# usage: rubrik_mv_op.ksh -d <DBNAME> -v <logs|data> -o <open|close>
#
# -d Oracle DBNAME
# -v Volume to operate on, logs or data
# -o Operation to perform - open or close the MV
get_script_dir() {
# Portable way to get script directory for Linux and HP/UX
local src="$0"
# 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")"
[[ $src != /* ]] && src="$dir/$src"
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
cd -P $(dirname "$src") >/dev/null 2>&1 && pwd
}
MYDIR="$(get_script_dir)"
source $MYDIR/rbk_api.conf
source $MYDIR/oracle_funcs.sh
MYDIR=$(get_script_dir)
. $MYDIR/rbk_api.conf
. $MYDIR/oracle_funcs.ksh
usage() { echo "Usage: $0 -d <DBNAME> -v <logs|data> -o <open|close>" 1>&2; exit 1; }
usage() {
echo "Usage: $0 -d <DBNAME> -v <logs|data> -o <open|close>" 1>&2
exit 1
}
force=0