Compare commits

...

5 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
14b1d29384 gitignore 2025-10-28 12:22:56 -04:00
024d06a827 Adding simple tests 2025-10-28 12:22:46 -04:00
10 changed files with 307 additions and 109 deletions

5
.gitignore vendored
View File

@@ -6,6 +6,7 @@ __pycache__/
env/ env/
venv/ venv/
ENV/ ENV/
SCRATCH
# macOS system files # macOS system files
.DS_Store .DS_Store
@@ -16,7 +17,11 @@ ENV/
# Exclude Rubrik API config files # Exclude Rubrik API config files
rbk_api.conf rbk_api.conf
rubrik.conf
*.json
# Other common ignores # Other common ignores
*.swp *.swp
*.swo *.swo
releases/

82
check_date.ksh Executable file
View File

@@ -0,0 +1,82 @@
#!/usr/bin/ksh
echo "Checking date command availability and date arithmetic support..."
# Check for date commands
echo "Available date commands:"
if command -v date >/dev/null 2>&1; then
echo " date: $(which date)"
DATE_CMD="date"
else
echo " date: NOT FOUND"
fi
if command -v gdate >/dev/null 2>&1; then
echo " gdate: $(which gdate)"
if [ -z "$DATE_CMD" ]; then
DATE_CMD="gdate"
fi
else
echo " gdate: NOT FOUND in PATH"
# Check common HP-UX locations for gdate
echo " Checking common HP-UX locations for gdate..."
for gdate_path in /usr/local/bin/gdate /opt/gnu/bin/gdate /usr/contrib/bin/gdate /opt/coreutils/bin/gdate; do
if [ -x "$gdate_path" ]; then
echo " gdate: FOUND at $gdate_path"
if [ -z "$DATE_CMD" ]; then
DATE_CMD="$gdate_path"
fi
break
fi
done
if [ -z "$DATE_CMD" ] || [ "$DATE_CMD" = "date" ]; then
echo " gdate: NOT FOUND in common locations"
fi
fi
if command -v perl >/dev/null 2>&1; then
echo " perl: $(which perl)"
PERL_AVAILABLE=1
else
echo " perl: NOT FOUND"
PERL_AVAILABLE=0
fi
if [ -z "$DATE_CMD" ]; then
echo "ERROR: No date command found!"
exit 1
fi
echo ""
echo "Testing date arithmetic with: $DATE_CMD"
# Test basic date
echo "Basic date output:"
$DATE_CMD +"%Y-%m-%d %H:%M:%S"
# Test date arithmetic like used in rman_db.ksh
echo ""
echo "Testing date arithmetic: '$DATE_CMD +%m-%d-%Y\ %H:%M:%S -d \"-1 hour\"'"
if $DATE_CMD -d "-1 hour" >/dev/null 2>&1; then
RESULT=$($DATE_CMD +%m-%d-%Y\ %H:%M:%S -d '-1 hour')
echo "SUCCESS: Date arithmetic works"
echo "Result: $RESULT"
else
echo "ERROR: Date arithmetic (-d option) not supported"
echo "This system may need GNU date (gdate) installed"
fi
# Test perl-based date arithmetic as fallback
if [ $PERL_AVAILABLE -eq 1 ]; then
echo ""
echo "Testing perl-based date arithmetic fallback:"
echo "Command: perl -e 'use POSIX qw(strftime); \$time = time() - 3600; print strftime(\"%m-%d-%Y %H:%M:%S\", localtime(\$time))'"
PERL_RESULT=$(perl -e 'use POSIX qw(strftime); $time = time() - 3600; print strftime("%m-%d-%Y %H:%M:%S", localtime($time))')
echo "SUCCESS: Perl date arithmetic works"
echo "Result: $PERL_RESULT"
else
echo ""
echo "WARNING: Perl not available - no fallback for date arithmetic"
fi
echo ""
echo "Test complete."

View File

@@ -5,13 +5,26 @@
# v1.1 - James Pattinson - October 2025 # v1.1 - James Pattinson - October 2025
# #
# usage: list_mv.ksh # usage: list_mv.ksh
_SCRIPT_="$0"
get_script_dir() { get_script_dir() {
src="$0" script="$1"
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd) case "$script" in
echo "$dir" /*) 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/rubrik.conf
. $MYDIR/oracle_funcs.ksh . $MYDIR/oracle_funcs.ksh
@@ -45,3 +58,4 @@ awk '
' /tmp/rbkresponse.$$ ' /tmp/rbkresponse.$$
cleanup cleanup

View File

@@ -2,7 +2,7 @@
# #
# Oracle shell script support functions # Oracle shell script support functions
# Written for HCL / Nokia # Written for HCL / Nokia
# v1.0 - James Pattinson - October 2025 # v1.0 - James Pattinson - November 2025
nowait=0 nowait=0
@@ -13,11 +13,18 @@ tabwidth=25
# Portable short hostname function # Portable short hostname function
get_short_hostname() { 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 if hostname -s >/dev/null 2>&1; then
hostname -s hostname -s
else else
hostname | awk -F. '{print $1}' hostname | awk -F. '{print $1}'
fi fi
fi
} }
HOST=$(get_short_hostname) HOST=$(get_short_hostname)
@@ -73,10 +80,11 @@ exit_with_error() {
check_http_error() { check_http_error() {
# All good responses start with a 2 # 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: echo FATAL: HTTP error from API call: $http_response. The server responded with:
cat /tmp/rbkresponse.$$ ; echo ; exit_with_error cat /tmp/rbkresponse.$$ ; echo ; exit_with_error
fi fi
} }
check_pid() { check_pid() {
@@ -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.$$) 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.$$) 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 echo ERROR: MV with name $mv_name was not found
exit_with_error exit_with_error
fi fi
@@ -219,7 +227,7 @@ get_mv() {
get_data_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" ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get 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.$$) 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.$$) 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 echo ERROR: MV with name $mv_name was not found
exit_with_error exit_with_error
fi fi
@@ -238,16 +246,16 @@ get_log_mv() {
# Look for a log volume. If not present, return the data volume # 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" ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get 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.$$) 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" echo "INFO: Log volume ($mv_name) not found. Logs will be written to DB volume"
logMvPresent=0 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" ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
rest_api_get 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.$$) 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.$$) 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 echo ERROR: MV with name $mv_name was not found
exit_with_error exit_with_error
fi 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() { open_mv() {
PIDFILE=/tmp/mvLock_${mv_name}.pid PIDFILE=/tmp/mvLock_${mv_name}.pid

View File

@@ -1,26 +0,0 @@
# ID and Key for RSC Service Account (starts with client|) (use single quotes)
ID='client|xxxxxxxxxxxxxxxxxxx'
SECRET=xxxxxxxxxxxxxxxxxxxxxxxx
# DNS name of Rubrik CDM
RUBRIK_IP=<CDM address>
# Oracle Settings
MOUNTPOINT_PREFIX=/rubrik_
# How many hours of archivelog to keep on host. 0 means do not purge logs
HOSTLOGRET=2
# Percentage threshold to warn if an MV filesystem is getting full
MV_SPACE_WARN=75
# Logging directories
# API calls
API_LOG_DIR=/tmp/rubrik
# RMAN sessions
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

View File

@@ -2,32 +2,38 @@
# #
# RMAN DB backup with incremental Merge # RMAN DB backup with incremental Merge
# Written for HCL / Nokia # Written for HCL / Nokia
# v1.0 - James Pattinson - October 2025 # v1.0 - James Pattinson - November 2025
# #
# usage: rman_db.ksh <ORACLE_SID> # usage: rman_db.ksh <ORACLE_SID>
_SCRIPT_="$0"
get_script_dir() { get_script_dir() {
src="$0" script="$1"
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd) case "$script" in
echo "$dir" /*) 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 MYDIR=$(get_script_dir "$_SCRIPT_")
# . $HOME/.profile
export ORAENV_ASK=NO
export ORACLE_SID=$1
. oraenv
export ORAENV_ASK=YES
. $MYDIR/rubrik.conf . $MYDIR/rubrik.conf
. $MYDIR/oracle_funcs.ksh . $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() { usage() {
echo "Usage: $0 <DBNAME>]" 1>&2 echo "Usage: $0 <DBNAME>]" 1>&2
@@ -38,16 +44,13 @@ if [ -z "${ORACLE_SID}" ]; then
usage usage
fi fi
export NLS_DATE_FORMAT='mm-dd-yyyy hh24:mi:ss'
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
MOUNTPOINT=$MOUNTPOINT_PREFIX/$ORACLE_SID/data MOUNTPOINT=$MOUNTPOINT_PREFIX/$ORACLE_SID/data
mkdir -p $RMAN_LOG_DIR/$ORACLE_SID/ mkdir -p $RMAN_LOG_DIR/$ORACLE_SID/
RMAN_LOG=$RMAN_LOG_DIR/$ORACLE_SID/rman_${ORACLE_SID}_DB_$(date +%d%m%y).log RMAN_LOG=$RMAN_LOG_DIR/$ORACLE_SID/rman_${ORACLE_SID}_DB_$(date +%d%m%y).log
# Disk space check # 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 if [ "$dusage" != "" ]; then
echo "WARNING: Disk Space Alert - sending email" echo "WARNING: Disk Space Alert - sending email"
echo "$dusage" | mailx -s "WARNING: Rubrik MV Disk Space Alert On $(hostname) at $(date)" $ALERT_EMAILS 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 fi
# Change permission of backup files to enable alternate host restore # 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 close_mv

View File

@@ -2,30 +2,39 @@
# #
# RMAN Log backup # RMAN Log backup
# Written for HCL / Nokia # Written for HCL / Nokia
# v1.1 - James Pattinson - October 2025 # v1.1 - James Pattinson - November 2025
# #
# usage: rman_logs.ksh <ORACLE_SID> # usage: rman_logs.ksh <ORACLE_SID>
_SCRIPT_="$0"
get_script_dir() { get_script_dir() {
src="$0" script="$1"
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd) case "$script" in
echo "$dir" /*) 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 MYDIR=$(get_script_dir "$_SCRIPT_")
export ORAENV_ASK=NO
export ORACLE_SID=$1
. oraenv
export ORAENV_ASK=YES
. $MYDIR/rubrik.conf . $MYDIR/rubrik.conf
. $MYDIR/oracle_funcs.ksh . $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() { usage() {
echo "Usage: $0 <DBNAME>]" 1>&2 echo "Usage: $0 <DBNAME>]" 1>&2
exit 1 exit 1
@@ -35,24 +44,26 @@ if [ -z "${ORACLE_SID}" ]; then
usage usage
fi fi
export NLS_DATE_FORMAT='mm-dd-yyyy hh24:mi:ss'
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
mkdir -p $RMAN_LOG_DIR/$ORACLE_SID/ mkdir -p $RMAN_LOG_DIR/$ORACLE_SID/
RMAN_LOG=$RMAN_LOG_DIR/$ORACLE_SID/rman_${ORACLE_SID}_LOG_$(date +%d%m%y).log RMAN_LOG=$RMAN_LOG_DIR/$ORACLE_SID/rman_${ORACLE_SID}_LOG_$(date +%d%m%y).log
get_log_mv get_log_mv
open_mv open_mv
if [ -z "$numChannels" ]; then
echo "WARNING: numChannels not found, setting to 1"
numChannels=1
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo ERROR: Unable to open MV, aborting echo ERROR: Unable to open MV, aborting
exit_with_error exit_with_error
fi fi
MOUNTPOINT=$MOUNTPOINT_PREFIX/$ORACLE_SID/logs MOUNTPOINT=$MOUNTPOINT_PREFIX/$ORACLE_SID/log
# Disk space check # 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 if [ "$dusage" != "" ]; then
echo "WARNING: Disk Space Alert - sending email" echo "WARNING: Disk Space Alert - sending email"
echo "$dusage" | mailx -s "WARNING: Rubrik MV Disk Space Alert On $(hostname) at $(date)" $ALERT_EMAILS 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 fi
# Change permission of backup files to enable alternate host restore # 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 close_mv

View File

@@ -28,4 +28,4 @@ RMAN_LOG_DIR=/tmp/rubrik/rman
# List of email addresses to send failure alerts to # List of email addresses to send failure alerts to
ALERT_EMAILS=root,oracle ALERT_EMAILS=root,oracle
# Set to 1 to enable email alert on success also # 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 # -v Volume to operate on, logs or data
# -o Operation to perform - open or close the MV # -o Operation to perform - open or close the MV
_SCRIPT_="$0"
get_script_dir() { get_script_dir() {
src="$0" script="$1"
dir=$(cd -P "$(dirname "$src")" >/dev/null 2>&1 && pwd) case "$script" in
echo "$dir" /*) 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 . $MYDIR/oracle_funcs.ksh
usage() { 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 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 case "${o}" in
d) d)
DBNAME=${OPTARG} DBNAME=${OPTARG}
@@ -37,6 +59,9 @@ while getopts "d:v:o:" o; do
o) o)
OPCODE=${OPTARG} OPCODE=${OPTARG}
;; ;;
n)
MVNAME=${OPTARG}
;;
*) *)
usage usage
;; ;;
@@ -44,20 +69,36 @@ while getopts "d:v:o:" o; do
done done
shift $((OPTIND-1)) 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 usage
fi fi
# Script starts here # Script starts here
get_short_hostname() { 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 if hostname -s >/dev/null 2>&1; then
hostname -s hostname -s
else else
hostname | awk -F. '{print $1}' hostname | awk -F. '{print $1}'
fi fi
fi
} }
mv_name=$(get_short_hostname)_${DBNAME}_${VOLUME}
get_mv get_mv
case $OPCODE in case $OPCODE in

50
test.ksh Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/ksh
echo "Testing HP-UX compatibility for Rubrik scripts..."
# Check for required commands
for cmd in ksh awk readlink egrep date dfsdf expr mkdir; do
if ! command -v $cmd >/dev/null 2>&1; then
echo "ERROR: $cmd not found in PATH"
else
echo "OK: $cmd found"
fi
done
# Test awk JSON extraction for numChannels
echo '{"numChannels": 4, "foo": "bar"}' > /tmp/testjson.$$
numChannels=$(awk '{match($0, /"numChannels":[ ]*[0-9]+/); if (RSTART > 0) {val=substr($0, RSTART, RLENGTH); sub(/.*:[ ]*/, "", val); print val}}' /tmp/testjson.$$)
if [ "$numChannels" = "4" ]; then
echo "OK: awk numChannels extraction works"
else
echo "ERROR: awk numChannels extraction failed (got '$numChannels')"
fi
# Test awk JSON extraction for ManagedVolume
echo '{"id":"ManagedVolume:::abc-123-xyz"}' > /tmp/testjson.$$
mvId=$(awk '{match($0, /ManagedVolume:::[a-z0-9-]*/); if (RSTART > 0) {id=substr($0, RSTART, RLENGTH); sub(/"$/, "", id); print id}}' /tmp/testjson.$$)
if [ "$mvId" = "ManagedVolume:::abc-123-xyz" ]; then
echo "OK: awk ManagedVolume extraction works"
else
echo "ERROR: awk ManagedVolume extraction failed (got '$mvId')"
fi
# Test readlink
ln -s /tmp/testjson.$$ /tmp/testlink.$$
linkres=$(readlink /tmp/testlink.$$ 2>/dev/null)
if [ "$linkres" = "/tmp/testjson.$$" ]; then
echo "OK: readlink works"
else
echo "WARNING: readlink did not return expected result (got '$linkres')"
fi
rm -f /tmp/testjson.$$ /tmp/testlink.$$
# Test expr arithmetic
i=0
i=$(expr $i + 1)
if [ "$i" = "1" ]; then
echo "OK: expr arithmetic works"
else
echo "ERROR: expr arithmetic failed"
fi
echo "Testing complete."