hpux updates
This commit is contained in:
25
list_mv.sh
25
list_mv.sh
@@ -1,13 +1,23 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# List MVs using API call to CDM, for diagnostic purposes
|
||||
# List MVs using API call to RSC, for diagnostic purposes
|
||||
# Written for HCL / Nokia
|
||||
# v1.1 - James Pattinson - October 2025
|
||||
#
|
||||
# usage: list_mv.sh
|
||||
|
||||
|
||||
MYDIR="$(dirname "$(readlink -f "$0")")"
|
||||
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
|
||||
|
||||
@@ -15,18 +25,11 @@ source $MYDIR/oracle_funcs.sh
|
||||
|
||||
echo Service account in use is $ID
|
||||
|
||||
echo ALL MVs
|
||||
echo "Managed Volumes"
|
||||
|
||||
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume"
|
||||
rest_api_get
|
||||
|
||||
grep -Eo '"name"[^,]*' /tmp/rbkresponse.$$
|
||||
|
||||
echo NonRelic MVs
|
||||
|
||||
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?is_relic=false"
|
||||
rest_api_get
|
||||
|
||||
grep -Eo '"name"[^,]*' /tmp/rbkresponse.$$
|
||||
grep -o '"name":"[^"]*"' /tmp/rbkresponse.$$ | cut -d'"' -f4
|
||||
|
||||
cleanup
|
||||
|
||||
141
oracle_funcs.sh
141
oracle_funcs.sh
@@ -10,15 +10,41 @@ LOGFILE=$API_LOG_DIR/api_calls.log
|
||||
mkdir -p $API_LOG_DIR
|
||||
tabwidth=25
|
||||
|
||||
HOST=$(hostname -s)
|
||||
|
||||
os=$(uname -o)
|
||||
if [ $os == "Solaris" ]; then
|
||||
# Use the GNU version of date binary
|
||||
DATE=/usr/gnu/bin/date
|
||||
else
|
||||
DATE=$(which date)
|
||||
fi
|
||||
# Portable short hostname function
|
||||
get_short_hostname() {
|
||||
if hostname -s >/dev/null 2>&1; then
|
||||
hostname -s
|
||||
else
|
||||
hostname | awk -F. '{print $1}'
|
||||
fi
|
||||
}
|
||||
HOST=$(get_short_hostname)
|
||||
|
||||
|
||||
# Detect OS and set DATE variable appropriately
|
||||
os_name=$(uname -s)
|
||||
case "$os_name" in
|
||||
Linux)
|
||||
DATE=$(which date)
|
||||
;;
|
||||
SunOS)
|
||||
# Solaris
|
||||
DATE=/usr/gnu/bin/date
|
||||
;;
|
||||
HP-UX)
|
||||
# HP/UX: try gdate, fallback to date with warning
|
||||
if command -v gdate >/dev/null 2>&1; then
|
||||
DATE=$(command -v gdate)
|
||||
else
|
||||
DATE=$(command -v date)
|
||||
echo "WARNING: GNU date (gdate) not found. Date arithmetic may not work on HP/UX." >&2
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
DATE=$(which date)
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "`$DATE` -$$-: CALLED $0 $@" >> $LOGFILE
|
||||
|
||||
@@ -35,13 +61,13 @@ function ctrl_c_inhibit () {
|
||||
|
||||
exit_with_error () {
|
||||
# if [ $usingsatoken ]; then
|
||||
# ENDPOINT="https://$RUBRIK_IP/api/v1/session/me"
|
||||
# ENDPOINT="https://$RUBRIK_IP/api/internal/session/me"
|
||||
# rest_api_delete
|
||||
# check_http_error
|
||||
# fi
|
||||
|
||||
cat /tmp/rbkresponse.$$ | mailx -s "Backup error on ${HOST} for ${ORACLE_SID}. Please investigate" $ALERT_EMAILS
|
||||
rm -f /tmp/rbkresponse.$$
|
||||
#rm -f /tmp/rbkresponse.$$
|
||||
rm -f /tmp/mountedDBs.$$
|
||||
rm -f $PIDFILE
|
||||
echo Aborting Script!
|
||||
@@ -62,21 +88,23 @@ check_pid () {
|
||||
if [ -f $PIDFILE ]
|
||||
then
|
||||
PID=$(cat $PIDFILE)
|
||||
ps -p $PID > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "ERROR: MV already being used by process ID $PID"
|
||||
ps -fp $PID
|
||||
exit_with_error
|
||||
else
|
||||
## Process not found assume not running
|
||||
echo $$ > $PIDFILE
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "ERROR: Could not create mvLock file"
|
||||
exit_with_error
|
||||
fi
|
||||
fi
|
||||
if ps -p $PID > /dev/null 2>&1; then
|
||||
echo "ERROR: MV already being used by process ID $PID"
|
||||
if ps -fp $PID > /dev/null 2>&1; then
|
||||
ps -fp $PID
|
||||
else
|
||||
ps -ef | awk -v pid=$PID '$2==pid'
|
||||
fi
|
||||
exit_with_error
|
||||
else
|
||||
## Process not found assume not running
|
||||
echo $$ > $PIDFILE
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "ERROR: Could not create mvLock file"
|
||||
exit_with_error
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo $$ > $PIDFILE
|
||||
if [ $? -ne 0 ]
|
||||
@@ -88,28 +116,12 @@ check_pid () {
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Get a new token only if AUTH_TOKEN is not already set
|
||||
check_get_token () {
|
||||
|
||||
if [ -z "${AUTH_TOKEN}" ]; then
|
||||
|
||||
# RSC
|
||||
id_string=$(echo $ID | cut -d\| -f 2)
|
||||
# CDM
|
||||
id_string=$(echo $ID | cut -d: -f 4)
|
||||
|
||||
if [ -f ~/.rbksession.$id_string ]; then
|
||||
echo "`$DATE` -$$-: AUTH SESSION FILE EXISTS" >> $LOGFILE
|
||||
read expiration token < <(echo $(cat ~/.rbksession.$id_string))
|
||||
if [ $($DATE +%s -u -d $expiration) -lt $(( $($DATE +%s) + 1800 )) ]; then
|
||||
echo "`$DATE` -$$-: AUTH TOKEN EXPIRED" >> $LOGFILE
|
||||
get_token
|
||||
else
|
||||
AUTH_TOKEN=$token
|
||||
fi
|
||||
else
|
||||
get_token
|
||||
fi
|
||||
fi
|
||||
if [ -z "$AUTH_TOKEN" ]; then
|
||||
get_token
|
||||
fi
|
||||
}
|
||||
|
||||
get_token () {
|
||||
@@ -122,15 +134,12 @@ get_token () {
|
||||
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 -Eo '"token"[^,]*' /tmp/rbkresponse.$$ | grep -Eo '[^:]*$' | sed 's/\"//g')
|
||||
SESSION=$(grep -Eo '"sessionId"[^,]*' /tmp/rbkresponse.$$ | grep -Eo '[^:]*$' | sed 's/\"//g')
|
||||
EXPIRATION=$(grep -Eo '"expirationTime"[^,]*' /tmp/rbkresponse.$$ | cut -d: -f 2-4 | sed 's/\"//g' | sed 's/.000Z//;s/T/Z/')
|
||||
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/')
|
||||
|
||||
echo "`$DATE` -$$-: AUTH SESSION $SESSION" >> $LOGFILE
|
||||
echo "`$DATE` -$$-: SAVING TOKEN TO FILE" >> $LOGFILE
|
||||
echo "$EXPIRATION $AUTH_TOKEN" > ~/.rbksession.$id_string
|
||||
usingsatoken=1
|
||||
trap ctrl_c INT
|
||||
echo "`$DATE` -$$-: AUTH SESSION $SESSION" >> $LOGFILE
|
||||
trap ctrl_c INT
|
||||
}
|
||||
|
||||
# HTTP GET: Given $ENDPOINT write output to file
|
||||
@@ -205,8 +214,8 @@ get_mv () {
|
||||
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
|
||||
rest_api_get
|
||||
|
||||
mvId=$(grep -Eo '"id"[^,]*' /tmp/rbkresponse.$$ | grep -Eo 'ManagedVolume:::[a-z0-9-]*')
|
||||
numChannels=$(grep -Eo '"numChannels"[^,]*' /tmp/rbkresponse.$$ | cut -d: -f2)
|
||||
mvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
|
||||
numChannels=$(egrep '"numChannels"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}')
|
||||
|
||||
if [[ $mvId == "" ]]; then
|
||||
echo ERROR: MV with name $mv_name was not found
|
||||
@@ -222,8 +231,8 @@ get_data_mv () {
|
||||
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
|
||||
rest_api_get
|
||||
|
||||
mvId=$(grep -Eo '"id"[^,]*' /tmp/rbkresponse.$$ | grep -Eo 'ManagedVolume:::[a-z0-9-]*')
|
||||
numChannels=$(grep -Eo '"numChannels"[^,]*' /tmp/rbkresponse.$$ | cut -d: -f2)
|
||||
mvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
|
||||
numChannels=$(egrep '"numChannels"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}')
|
||||
|
||||
if [[ $mvId == "" ]]; then
|
||||
echo ERROR: MV with name $mv_name was not found
|
||||
@@ -240,7 +249,7 @@ get_log_mv () {
|
||||
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
|
||||
rest_api_get
|
||||
|
||||
logMvId=$(grep -Eo '"id"[^,]*' /tmp/rbkresponse.$$ | grep -Eo 'ManagedVolume:::[a-z0-9-]*')
|
||||
logMvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
|
||||
|
||||
if [[ $logMvId == "" ]]; then
|
||||
echo "INFO: Log volume ($mv_name) not found. Logs will be written to DB volume"
|
||||
@@ -250,16 +259,16 @@ get_log_mv () {
|
||||
ENDPOINT="https://$RUBRIK_IP/api/internal/managed_volume?name=$mv_name&is_relic=false"
|
||||
rest_api_get
|
||||
|
||||
mvId=$(grep -Eo '"id"[^,]*' /tmp/rbkresponse.$$ | grep -Eo 'ManagedVolume:::[a-z0-9-]*')
|
||||
numChannels=$(grep -Eo '"numChannels"[^,]*' /tmp/rbkresponse.$$ | cut -d: -f2)
|
||||
mvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
|
||||
numChannels=$(egrep '"numChannels"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}')
|
||||
|
||||
if [[ $mvId == "" ]]; then
|
||||
echo ERROR: MV with name $mv_name was not found
|
||||
exit_with_error
|
||||
fi
|
||||
else
|
||||
mvId=$(grep -Eo '"id"[^,]*' /tmp/rbkresponse.$$ | grep -Eo 'ManagedVolume:::[a-z0-9-]*')
|
||||
numChannels=$(grep -Eo '"numChannels"[^,]*' /tmp/rbkresponse.$$ | cut -d: -f2)
|
||||
mvId=$(egrep '"id"[^,]*' /tmp/rbkresponse.$$ | egrep -o 'ManagedVolume:::[a-z0-9-]*')
|
||||
numChannels=$(egrep '"numChannels"[^,]*' /tmp/rbkresponse.$$ | awk -F: '{print $2}')
|
||||
logMvPresent=1
|
||||
echo "INFO: Log volume ($mv_name) exists with $numChannels channels"
|
||||
fi
|
||||
@@ -294,11 +303,11 @@ close_mv () {
|
||||
|
||||
cleanup () {
|
||||
# if [ $usingsatoken ]; then
|
||||
# ENDPOINT="https://$RUBRIK_IP/api/v1/session/me"
|
||||
# ENDPOINT="https://$RUBRIK_IP/api/internal/session/me"
|
||||
# rest_api_delete
|
||||
# fi
|
||||
echo "`$DATE` -$$-: EXITED $0 $@" >> $LOGFILE
|
||||
rm -f /tmp/mountedDBs.$$
|
||||
rm -f /tmp/rbkresponse.$$
|
||||
#rm -f /tmp/mountedDBs.$$
|
||||
#rm -f /tmp/rbkresponse.$$
|
||||
rm -f $PIDFILE
|
||||
}
|
||||
|
||||
16
rman_db.sh
16
rman_db.sh
@@ -6,7 +6,17 @@
|
||||
#
|
||||
# usage: rman_db.sh <ORACLE_SID>
|
||||
|
||||
MYDIR="$(dirname "$(readlink -f "$0")")"
|
||||
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)"
|
||||
|
||||
export ORACLE_SID=$1
|
||||
|
||||
@@ -42,7 +52,7 @@ 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 | grep -E "$MOUNTPOINT" | sed s/%//g | awk -v spaceWarn=$MV_SPACE_WARN '{ if($5 >= spaceWarn) print $0;}')
|
||||
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
|
||||
@@ -116,6 +126,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
|
||||
16
rman_logs.sh
16
rman_logs.sh
@@ -6,7 +6,17 @@
|
||||
#
|
||||
# usage: rman_logs.sh <ORACLE_SID>
|
||||
|
||||
MYDIR="$(dirname "$(readlink -f "$0")")"
|
||||
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)"
|
||||
export ORACLE_SID=$1
|
||||
|
||||
. $HOME/.profile
|
||||
@@ -53,7 +63,7 @@ else
|
||||
fi
|
||||
|
||||
# Disk space check
|
||||
dusage=$(df -Ph | grep -E "$MOUNTPOINT" | sed s/%//g | awk -v spaceWarn=$MV_SPACE_WARN '{ if($5 >= spaceWarn) print $0;}')
|
||||
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
|
||||
@@ -107,7 +117,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
|
||||
|
||||
|
||||
@@ -10,7 +10,17 @@
|
||||
# -v Volume to operate on, logs or data
|
||||
# -o Operation to perform - open or close the MV
|
||||
|
||||
MYDIR="$(dirname "$(readlink -f "$0")")"
|
||||
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
|
||||
|
||||
@@ -42,7 +52,14 @@ fi
|
||||
|
||||
# Script starts here
|
||||
|
||||
mv_name=$(hostname -s)_${DBNAME}_${VOLUME}
|
||||
get_short_hostname() {
|
||||
if hostname -s >/dev/null 2>&1; then
|
||||
hostname -s
|
||||
else
|
||||
hostname | awk -F. '{print $1}'
|
||||
fi
|
||||
}
|
||||
mv_name=$(get_short_hostname)_${DBNAME}_${VOLUME}
|
||||
get_mv
|
||||
|
||||
case $OPCODE in
|
||||
|
||||
Reference in New Issue
Block a user