136 lines
3.7 KiB
Bash
136 lines
3.7 KiB
Bash
#!/bin/bash
|
|
|
|
function usage {
|
|
echo "Usage: crdb -n|--name <DB_NAME> -v|--version <19|21>"
|
|
}
|
|
|
|
########
|
|
# MAIN #
|
|
########
|
|
|
|
# parameter processing
|
|
while [ "$1" != "" ]; do
|
|
case $1 in
|
|
-n | --name ) shift
|
|
DB_NAME="$1"
|
|
;;
|
|
-v | --version ) shift
|
|
VERSION="$1"
|
|
;;
|
|
* ) usage
|
|
exit 1
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [ -z "${DB_NAME}" ] || [ -z "${VERSION}" ]
|
|
then
|
|
usage
|
|
exit -2
|
|
fi
|
|
|
|
# version/template selection
|
|
if [ "$VERSION" == "21" ]; then
|
|
. oraenv <<EOF!
|
|
SET21
|
|
EOF!
|
|
export ORACLE_SID=${DB_NAME}PRD
|
|
BACKUP_DB_NAME=ASTY
|
|
BACKUP_DIR=/mnt/yavin4/tech/oracle/orabackup/_keep_/Standalone/21
|
|
echo "spfile='${ORACLE_BASE}/admin/${ORACLE_SID}/spfile/spfile${ORACLE_SID}.ora'" > ${ORACLE_BASE}/dbs/init${ORACLE_SID}.ora
|
|
fi
|
|
|
|
if [ "$VERSION" == "19" ]; then
|
|
. oraenv <<EOF!
|
|
SET19
|
|
EOF!
|
|
export ORACLE_SID=${DB_NAME}PRD
|
|
BACKUP_DB_NAME=ASTY
|
|
BACKUP_DIR=/mnt/yavin4/tech/oracle/orabackup/_keep_/Standalone/19
|
|
echo "spfile='${ORACLE_BASE}/admin/${ORACLE_SID}/spfile/spfile${ORACLE_SID}.ora'" > ${ORACLE_BASE}/dbs/init${ORACLE_SID}.ora
|
|
fi
|
|
|
|
|
|
if [ -z "${BACKUP_DIR}" ]
|
|
then
|
|
echo "No template found for this database version"
|
|
exit -1
|
|
fi
|
|
|
|
# admin directories creation
|
|
mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/adump
|
|
mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile
|
|
mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/spfile
|
|
mkdir -p ${ORACLE_BASE}/admin/${ORACLE_SID}/divers
|
|
|
|
|
|
# init and spfile creation
|
|
cp ${BACKUP_DIR}/init${BACKUP_DB_NAME}PRD.ora ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora
|
|
sed -i -r "s/${BACKUP_DB_NAME}/${DB_NAME}/" ${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora
|
|
|
|
echo ${ORACLE_SID}
|
|
sqlplus /nolog <<EOF!
|
|
connect / as sysdba
|
|
create spfile='${ORACLE_BASE}/admin/${ORACLE_SID}/spfile/spfile${ORACLE_SID}.ora' from pfile='${ORACLE_BASE}/admin/${ORACLE_SID}/pfile/init${ORACLE_SID}.ora';
|
|
startup nomount;
|
|
EOF!
|
|
|
|
# duplicate from template
|
|
rman auxiliary / <<EOF!
|
|
run
|
|
{
|
|
allocate auxiliary channel aux01 device type disk;
|
|
allocate auxiliary channel aux02 device type disk;
|
|
allocate auxiliary channel aux03 device type disk;
|
|
allocate auxiliary channel aux04 device type disk;
|
|
allocate auxiliary channel aux05 device type disk;
|
|
allocate auxiliary channel aux06 device type disk;
|
|
allocate auxiliary channel aux07 device type disk;
|
|
allocate auxiliary channel aux08 device type disk;
|
|
allocate auxiliary channel aux09 device type disk;
|
|
allocate auxiliary channel aux10 device type disk;
|
|
duplicate target database to ${DB_NAME} backup location '${BACKUP_DIR}/backupset/';
|
|
}
|
|
EOF!
|
|
|
|
sqlplus /nolog <<EOF!
|
|
connect / as sysdba
|
|
shutdown immediate;
|
|
startup;
|
|
EOF!
|
|
|
|
# datapatch & recompile
|
|
cd ${ORACLE_HOME}/OPatch
|
|
./datapatch
|
|
sqlplus /nolog <<EOF!
|
|
connect / as sysdba
|
|
@$ORACLE_HOME/rdbms/admin/utlrp
|
|
-- recompile all in PDB$SEED
|
|
alter pluggable database PDB\$SEED close immediate instances=ALL;
|
|
alter pluggable database PDB\$SEED open read write instances=ALL;
|
|
alter session set container=PDB\$SEED;
|
|
alter session set "_ORACLE_SCRIPT"=true;
|
|
@?/rdbms/admin/utlrp
|
|
alter session set "_ORACLE_SCRIPT"=false;
|
|
alter session set container=CDB\$ROOT;
|
|
alter pluggable database PDB\$SEED close immediate instances=ALL;
|
|
alter pluggable database PDB\$SEED open read only instances=ALL;
|
|
EOF!
|
|
|
|
# NEWID
|
|
sqlplus /nolog <<EOF!
|
|
connect / as sysdba
|
|
shutdown immediate;
|
|
startup mount exclusive;
|
|
EOF!
|
|
|
|
nid TARGET=/ LOGFILE=/tmp/nid.log
|
|
|
|
sqlplus /nolog <<EOF!
|
|
connect / as sysdba
|
|
startup mount exclusive;
|
|
alter database open resetlogs;
|
|
shutdown immediate;
|
|
startup;
|
|
EOF!
|