Skip to content

Commit

Permalink
Merge branch 'main' into 4459
Browse files Browse the repository at this point in the history
  • Loading branch information
boonware authored Dec 6, 2024
2 parents 340f4bb + d9c7d1b commit 683115f
Show file tree
Hide file tree
Showing 53 changed files with 5,189 additions and 34 deletions.
Binary file not shown.
3 changes: 3 additions & 0 deletions instance-applications/120-ibm-db2u-database/files/.Prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
CUST=`db2 list applications for db bludb show detail | awk '{print $1}' | grep -vi db2inst | grep -vi ctginst | tail -2 | head -1`
PS1='[${USER}@${HOSTNAME} - ${CUST} ${PWD##*/}]\$ '
17 changes: 17 additions & 0 deletions instance-applications/120-ibm-db2u-database/files/CheckCOS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
. /mnt/backup/bin/.PROPS

echo " "
echo " ##### BUCKET = ${CONTAINER} #####"
echo " "


. /mnt/backup/bin/.PROPS

DB2V=`db2level | grep Inform | awk '{print $5}' | sed 's/",//'`
if [ ${DB2V} = "v11.5.7.0" ]
then

db2RemStgManager S3 list server=${SERVER} auth1=${PARM1} auth2=${PARM2} container=${CONTAINER}
else
db2RemStgManager ALIAS LIST source=DB2REMOTE://AWSCOS//
fi
63 changes: 63 additions & 0 deletions instance-applications/120-ibm-db2u-database/files/CopyDBScripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# Finding the Instance owner
INSTOWNER=`/usr/local/bin/db2greg -dump | grep -ae "I," | grep -v "/das," | awk -F ',' '{print $4}' `

# Finding Instnace owner Group
GRPID=`cat /etc/passwd | grep ${INSTOWNER} | cut -d: -f4`
INSTGROUP=`cat /etc/group | grep ${GRPID} | cut -d: -f1`

# Find the home directory
INSTHOME=` cat /etc/passwd | grep ${INSTOWNER} | cut -d: -f6`

# Resolving INSTOWNER's executables path (sqllib):
DBPATH=`/usr/local/bin/db2greg -dump | grep -ae "I," | grep -v "/das," | grep "${INSTOWNER}" | awk -F ',' '{print $5}' `

# Source the db2profile for the root user to be able to issue several db2 commands locally:
SOURCEPATH="$DBPATH/db2profile"
. $SOURCEPATH

cd /tmp/db2-scripts/

echo -e "\nCopying the files to bin directory under Instance Home . . . "
cp -rp .Prompt ${INSTHOME}/
cp -rp CheckCOS.sh ${INSTHOME}/bin/
cp -rp DB2_Backup.sh ${INSTHOME}/bin/
cp -rp Run_Backup.sh ${INSTHOME}/bin/
cp -rp RUNEXPORT.sh ${INSTHOME}/bin/
cp -rp Explain.ddl ${INSTHOME}/bin/
cp -rp RUN_OnDemandFULL_BKP.sh ${INSTHOME}/bin/
cp -rp runstats_rebind.sh ${INSTHOME}/bin/
cp -rp CreateRoles.sh ${INSTHOME}/bin/
cp -rp grant_check.sh ${INSTHOME}/bin/
cp -rp reorgTablesIndexesInplace2.sh ${INSTHOME}/bin/
cp -rp extract_authorization.sh ${INSTHOME}/bin
cp -rp HADRMON.sh ${INSTHOME}/bin

echo -e "\nCopying the file to bin/ITCS104 directory under Instance Home . . ."
cp -rp FixInvalidObjects.sh ${INSTHOME}/bin/ITCS104/

echo -e "\nCopying files to /mnt/backup/bin directory . . .";
sudo cp -rp cronRunBKP.sh /mnt/backup/bin/
sudo chown db2uadm:wheel /mnt/backup/bin/cronRunBKP.sh

echo -e "\nCopying files to Managed directory under Instance Home . . .";
cp -rp Set_DB_COS_Storage.sh ${INSTHOME}/Managed/
cp -rp Reg-Large_TBSP.sh ${INSTHOME}/Managed/
cp PostBackFlow.sh ${INSTHOME}/Managed
cp OwnerCheck.txt ${INSTHOME}/Managed

echo -e "\nCopying files to maintenance directory under Instance Home . . . ";
cp -rp reorgTablesIndexesInplace2_maintenance.sh ${INSTHOME}/maintenance/reorgTablesIndexesInplace2.sh
if [ ! -d ${INSTHOME}/maintenance/logs ] ; then
mkdir -p ${INSTHOME}/maintenance/logs
echo "${DATETIME}:Creating directory ${INSTHOME}/maintenance/logs"
if [ $? != "0" ] ; then
echo "${DATETIME}: ERROR: Unable to create directory ${INSTHOME}/maintenance/logs"
exit 1
fi
fi

sudo chown -R ${INSTOWNER}:${INSTGROUP} ${INSTHOME}/bin
sudo chown -R ${INSTOWNER}:${INSTGROUP} ${INSTHOME}/maintenance
sudo chown -R ${INSTOWNER}:${INSTGROUP} ${INSTHOME}/Managed
125 changes: 125 additions & 0 deletions instance-applications/120-ibm-db2u-database/files/CreateRoles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/bash
## CreateRoles.sh
########## ${SCHEMANAME} ########
################################################################################
#
# Usage: ./CreateRoles.sh <SCHEMA NAME>
#
#
################################################################################

##Possibly need to grant the following on the non flex databases
## db2 "grant execute on package nullid.SQLC2K26 to role maximo_read"
## db2 "GRANT USAGE ON WORKLOAD SYSDEFAULTUSERWORKLOAD role maximo_read"
## db2 "grant execute on package nullid.SYSSH200 to role maximo_read"
## db2 grant select on syscat.schemata to role maximo_read
## db2 grant select on syscat.tables to role maximo_read
## db2 grant select on syscat.indexes to role maximo_read
## db2 grant select on syscat.columns to role maximo_read

#set -x
db2 connect to bludb

SCHEMANAME=MAXIMO

DATETIME=`date +%Y%m%d_%H%M%S`;

ROLES=`db2 -x "select char(ROLENAME,30) as ROLENAME from syscat.roles"`
ROLE="${SCHEMANAME}_read"
echo "" > temp
if ! grep -iqw "${ROLE}" <<< "${ROLES}" ; then
echo "create role ${SCHEMANAME}_read;" > temp
fi
USER=${SCHEMANAME}_READ
WRITE=${SCHEMANAME}_WRITE

db2 "select
'GRANT SELECT ON TABLE '||
RTRIM(TABSCHEMA) || '.\"' || RTRIM(tabname)||'\" TO ROLE ${USER};'
from
syscat.tables
where tabschema = '${SCHEMANAME}'" >> temp


db2 "select
'GRANT SELECT ON table '||
RTRIM(viewSCHEMA) || '.' || RTRIM(viewname)||' TO ROLE ${USER};'
from
syscat.views
where viewschema = '${SCHEMANAME}'" >> temp
echo "grant selectin on schema MAXIMO to role MAXIMO_READ;" >> temp



cat temp | grep -i ${SCHEMANAME}_read > ${USER}.sql
rm temp
echo "GRANT CONNECT ON DATABASE TO ROLE ${USER};" >>${USER}.sql
#echo "GRANT USE OF TABLESPACE MAXDATA TO ROLE ${USER};" >> ${USER}.sql
db2 -tvf ${USER}.sql > ${USER}_${DATETIME}.out

echo "" > temp
ROLE="${SCHEMANAME}_write"
if ! grep -iqw "${ROLE}" <<< "${ROLES}" ; then
echo "create role ${SCHEMANAME}_write;" > temp
fi
echo "grant updatein on schema MAXIMO to role MAXIMO_WRITE;" >> temp
echo "grant deletein on schema MAXIMO to role MAXIMO_WRITE;" >> temp
echo "grant insertin on schema MAXIMO to role MAXIMO_WRITE;" >> temp
echo "grant selectin on schema MAXIMO to role MAXIMO_WRITE;" >> temp

db2 "select
'GRANT SELECT, insert, update, delete ON TABLE '||
RTRIM(TABSCHEMA) || '.\"' || RTRIM(tabname)||'\" TO ROLE ${WRITE};'
from
syscat.tables
where tabschema = '${SCHEMANAME}'" >> temp




cat temp | grep -i ${SCHEMANAME}_write > ${WRITE}.sql
rm temp
echo "GRANT CONNECT ON DATABASE TO ROLE ${USER};" >>${WRITE}.sql
#echo "GRANT USE OF TABLESPACE MAXDATA TO ROLE ${WRITE};" >> ${WRITE}.sql

echo "" > temp
ROLE="${SCHEMANAME}_SEQ"
if ! grep -iqw "${ROLE}" <<< "${ROLES}" ; then
echo "create role ${SCHEMANAME}_SEQ;" > temp
fi
USER=${SCHEMANAME}_SEQ


db2 "select
'GRANT USAGE ON SEQUENCE '||
RTRIM(SEQSCHEMA) || '.\"' || RTRIM(SEQNAME)||'\" TO ROLE ${USER};'
from syscat.sequences where seqschema = '${SCHEMANAME}'" >> temp

cat temp | grep -i ${USER} > ${USER}.sql
rm temp
echo "GRANT CONNECT ON DATABASE TO ROLE ${USER};" >>${USER}.sql


db2 -tvf ${USER}.sql > ${USER}_${DATETIME}.out
db2 -tvf ${WRITE}.sql > ${WRITE}_${DATETIME}.out


db2 "grant selectin on schema MAXIMO to role MAXIMO_READ"
db2 "grant updatein on schema MAXIMO to role MAXIMO_WRITE"
db2 "grant deletein on schema MAXIMO to role MAXIMO_WRITE"
db2 "grant insertin on schema MAXIMO to role MAXIMO_WRITE"
db2 "grant selectin on schema MAXIMO to role MAXIMO_WRITE"

echo "Creating the EXPLAIN ROLE"
ROLE="EXPLAIN"
if grep -iqw "${ROLE}" <<< "${ROLES}" ; then

echo "${ROLE} is already present in the database ${DBNAME}";
exit 1;
else
echo "${ROLE} is Not FOUND, proceeding with creating the role "
db2 -tvf Explain.ddl
fi


db2 terminate
Loading

0 comments on commit 683115f

Please sign in to comment.