1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
#!/bin/bash F_usage() { cat <<EOF Purpose : Management of Golden Images (Oracle Homes) Usage : To list the available images: $0 -l To install an image on the localhost: $0 -i goldenimage [-n newname] [-r] To create an image based on the current OH: $0 -c [-n newname] [ -f ] To remove a golden image from the repository: $0 -d goldenimage [ -f ] Options : -l List the available Oracle Homes in the golden image repository -i goldenimage Installs locally the specified golden image. (If already deployed, an error is thrown) if the option -l is given, the list action has the priority over the deploy. -n newname Specify a new name for the Oracle Home: use it in case you need to patch and create a new Golden Image from it or if you want to change the Golden Image name for the current Oracle Home you are converting to Image. When creating a new Image (-c), it takes the basename of the OH by default, and not the OHname inside the inventory. -c Creates a new Golden Image from the current Oracle Home. -d goldenimage Removes the golden image from the repository -f If the Golden Image to be created exists, force the overwrite. -r Link with RAC option (install only) Example : $0 -i DB12_1_0_2_BP170718_home1 -n DB12_1_0_2_BP171018_home1 installs the Oracle Home DB12_1_0_2_BP170718_home1 with new name DB12_1_0_2_BP171018_home1 in order to apply the Bundle Patch 171018 on it $0 -i DB12_1_0_2_BP170718_home1 installs the Oracle Home DB12_1_0_2_BP170718_home1 for normal usage $0 -c -n DB12_1_0_2_BP180116 Creates a new Golden Image named DB12_1_0_2_BP180116 from the current ORACLE_HOME $0 -c -f Creates a new Golden Image with the name of the current OH basename, overwriting the eventual current image. E.g. if the current OH is /ccv/app/oracle/product/DB12_1_0_2_BP180116_RAC, the new GI name will be "DB12_1_0_2_BP180116_RAC" EOF } function F_colordef () { ####################################### # define colors for bash candiness # colxxx = foreground plain # colbxxx = foreground bold # coluxxx = foreground underline # colbgxxx = background # blk=black grn=green ylw=yellow pur=purple cyn=cyan wht=white # They must be used with echo -e $colxxx colblk='\e[0;30m' # Black - Regular colred='\e[0;31m' # Red colgrn='\e[0;32m' # Green colylw='\e[0;33m' # Yellow colblu='\e[0;34m' # Blue colpur='\e[0;35m' # Purple colcyn='\e[0;36m' # Cyan colwht='\e[0;37m' # White colbblk='\e[1;30m' # Black - Bold colbred='\e[1;31m' # Red colbgrn='\e[1;32m' # Green colbylw='\e[1;33m' # Yellow colbblu='\e[1;34m' # Blue colbpur='\e[1;35m' # Purple colbcyn='\e[1;36m' # Cyan colbwht='\e[1;37m' # White colublk='\e[4;30m' # Black - Underline colured='\e[4;31m' # Red colugrn='\e[4;32m' # Green coluylw='\e[4;33m' # Yellow colublu='\e[4;34m' # Blue colupur='\e[4;35m' # Purple colucyn='\e[4;36m' # Cyan coluwht='\e[4;37m' # White colbgblk='\e[40m' # Black - Background colbgred='\e[41m' # Red colbggrn='\e[42m' # Green colbgylw='\e[43m' # Yellow colbgblu='\e[44m' # Blue colbgpur='\e[45m' # Purple colbgcyn='\e[46m' # Cyan colbgwht='\e[47m' # White colrst='\e[0m' # Text Reset } F_list_OH () { F_colordef echo echo "Listing existing golden images:" RESULT=`$SQLPLUS -S -L ${REPO_CREDENTIALS} <<EOF | grep ";" set line 200 pages 1000 set feed off head off col name format a32 alter session set nls_timestamp_format='YYYY-MM-DD'; select name||';'||created||';'||fullpath from oh_golden_images order by created desc; EOF ` echo printf "%-35s %-10s %-18s\n" "OH_Name" "Created" "Installed locally?" echo "----------------------------------- ---------- ------------------" for line in $RESULT ; do L_GI_Name=`echo $line | awk -F\; '{print $1}'` L_GI_Date=`echo $line | awk -F\; '{print $2}'` L_GI_Path=`echo $line | awk -F\; '{print $3}'` L_Installed=`F_OH_Installed "$L_GI_Name"` printf "%-35s %-10s %-18s\n" "$L_GI_Name" "$L_GI_Date" "$L_Installed" done } F_OH_Installed () { CENTRAL_ORAINV=`grep ^inventory_loc /etc/oraInst.loc | awk -F= '{print $2}'` grep "<HOME NAME=\"$1\"" $CENTRAL_ORAINV/ContentsXML/inventory.xml | grep -v "REMOVED=\"T\"" >/dev/null if [ $? -eq 0 ] ; then echo -e "${colgrn}Installed${colrst}" else echo "Not installed" fi } F_OH_Component () { comp_file=$ORACLE_HOME/inventory/ContentsXML/comps.xml comp_xml=`grep "COMP NAME" $comp_file | head -1`; comp_name=`echo $comp_xml | tr ' ' '\n' | grep ^NAME= | awk -F\" '{print $2}'`; echo $comp_name } F_OH_Version () { comp_file=$ORACLE_HOME/inventory/ContentsXML/comps.xml comp_xml=`grep "COMP NAME" $comp_file | head -1`; comp_name=`echo $comp_xml | tr ' ' '\n' | grep ^NAME= | awk -F\" '{print $2}'`; comp_vers=`echo $comp_xml | tr ' ' '\n' | grep ^VER= | awk -F\" '{print $2}'`; if [ "$comp_name" == "oracle.server" ] ; then comp_vers=`grep "PATCH NAME=\"oracle.server\"" $comp_file 2>/dev/null | tr ' ' '\n' | grep ^VER= | awk -F\" '{print $2}'`; fi echo $comp_vers } F_Image_Exists () { L_search=$1 echo "Checking existence of image $L_search" $SQLPLUS -S -L ${REPO_CREDENTIALS} <<EOF | grep -e ";\|false" set line 200 pages 1000 set feed off head off col name format a32 alter session set nls_timestamp_format='YYYY-MM-DD'; select name||';'||created||';'||fullpath from oh_golden_images where name='${L_search}' union select 'false' from dual where not exists (select 1 from oh_golden_images where name='${L_search}'); EOF #select name||';'||created from oh_golden_images where name='${L_search}' ; } unset JAVA_HOME REPO_OWNER=scott REPO_PWD=tiger REPO_CONN="//localhost:1521/ORCL" REPO_CREDENTIALS=${REPO_OWNER}/${REPO_PWD}@${REPO_CONN} PRODUCT_INSTALL_PATH="/u01/app/oracle/product" GOLDEN_IMAGE_DEST="/share/oracle/oh_repository/golden_images" WORKING_COPY_DEST="/share/oracle/oh_repository/working_copies" while getopts "hli:n:cd:fr" OPTION ; do case "${OPTION}" in l) L_Action=list ;; i) L_Golden_Image=${OPTARG} L_Action=${L_Action:-install} if [[ "$L_Golden_Image" =~ [^a-zA-Z0-9_] ]] ; then echo "The OH name can contain only alphanumeric and underscores" exit 1 fi ;; n) L_New_Name=${OPTARG} if [[ "$L_New_Name" =~ [^a-zA-Z0-9_] ]] ; then echo "The OH name can contain only alphanumeric and underscores" exit 1 fi ;; c) L_Action=${L_Action:-create} ;; d) L_Golden_Image=${OPTARG} L_Action=${L_Action:-remove} ;; f) L_GI_Overwrite=yes ;; r) L_Link_RAC=yes ;; h) F_usage exit 1 ;; ?) F_usage exit 1 ;; esac done L_Action=${L_Action:-list} if [ $L_Action == "list" ] ; then setoh ic SQLPLUS=$ORACLE_HOME/sqlplus F_list_OH fi if [ $L_Action == "install" ] ; then setoh ic SQLPLUS=$ORACLE_HOME/sqlplus # if no new OH name specified, get the golden image name L_New_Name=${L_New_Name:-$L_Golden_Image} # - check if image to install exists RESULT=`F_Image_Exists $L_Golden_Image` if [ "$RESULT" == "false" ] ; then echo "The image $L_Golden_Image does not exist" exit 1 else echo "OK, the image exists." L_Image_Created=`echo $RESULT | awk -F\; '{print $2}'` L_Image_Path=`echo "$RESULT" | awk -F\; '{print $3}'` fi # - check if OH name to install is not already installed L_Installed=`F_OH_Installed "$L_New_Name"` if [ "$L_Installed" == "Installed" ] ; then echo "The image $L_New_Name is already installed on the local host. The script will exit." exit 1 fi # - check if the zip exists if [ -f $L_Image_Path ] ; then echo "Zip file exists." else echo "The image Zip file $L_Image_Path does NOT exist. The script will exit." exit 1 fi # - check if the destination directory exist L_Install_Path="${PRODUCT_INSTALL_PATH}/$L_New_Name" if [ -d $L_Install_Path ] ; then echo "The installation directory $l_Install_Path already exist. The script will exit." exit 1 fi # - create dest directory mkdir -p $L_Install_Path if [ $? -ne 0 ] ; then echo "Cannot create installation directory $l_Install_Path. The script will exit." exit 1 fi # - unzip the image from the zip unzip -q -d $L_Install_Path $L_Image_Path if [ $? -ne 0 ] ; then echo "The unzip failed. The script will exit." exit 1 else echo "The unzip completed successfully." fi # - clone the home with newname export ORACLE_HOME=$L_Install_Path SQLPLUS=$ORACLE_HOME/bin/sqlplus RUNINST=$ORACLE_HOME/oui/bin/runInstaller L_Clone_Command="$RUNINST -clone -waitForCompletion -silent ORACLE_HOME=$ORACLE_HOME ORACLE_BASE=$ORACLE_BASE ORACLE_HOME_NAME=$L_New_Name" echo $L_Clone_Command $L_Clone_Command if [ $? -eq 0 ] ; then echo "Clone command completed successfully." else echo "There was a problem during the clone command. The script will exit." exit 1 fi if [ "${L_Link_RAC}" == "yes" ] ; then pushd $ORACLE_HOME/rdbms/lib make -f ins_rdbms.mk rac_on make -f ins_rdbms.mk ioracle popd fi # - run setasmgid if [ -x /etc/oracle/setasmgid ] ; then echo "setasmgid found: running it on Oracle binary" /etc/oracle/setasmgid oracle_binary_path=$ORACLE_HOME/bin/oracle else echo "setasmgid not found: ignoring" fi # - create symlinks for ldap, sqlnet and tnsnames.ora TNS_ADMIN=${TNS_ADMIN:-/var/opt/oracle} ln -s $TNS_ADMIN/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora ln -s $TNS_ADMIN/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora ln -s $TNS_ADMIN/ldap.ora $ORACLE_HOME/network/admin/ldap.ora # - check if OH name installed exist in the central inventory L_Installed=`F_OH_Installed "$L_New_Name"` if [ "$L_Installed" != "Installed" ] ; then echo "The image $L_New_Name has been installed but it is not in the inventory. Please check." else echo "The image $L_New_Name has been installed and exists in the inventory." fi # - prompt to run root.sh to the user echo echo "Installation completed. Please run $ORACLE_HOME/root.sh as root before using the new home." fi if [ $L_Action == "create" ] ; then SQLPLUS=$ORACLE_HOME/bin/sqlplus # check that a Oracle Home is set if [ -z "ORACLE_HOME" ] ; then echo "ORACLE_HOME not set" exit 1 fi L_Component=`F_OH_Component $ORACLE_HOME` if [ "$L_Component" != "oracle.server" ] ; then echo "Please set a database ORACLE_HOME to create the Golden Image" exit 1 fi # if no new OH name specified, get the basename L_OH_Basename=`basename $ORACLE_HOME` L_New_Name=${L_New_Name:-$L_OH_Basename} # if golden image already exist, force is required RESULT=`F_Image_Exists $L_New_Name` if [ "$RESULT" != "false" ] ; then if [ "$L_GI_Overwrite" != "yes" ] ; then echo "Image $L_New_Name already exists but -f not specified. Exiting." exit 1 else echo "Image $L_New_Name already exists but -f specified. The script will continue." fi fi # Register Oracle Home in OH_REGISTRY # $SCRIPT_DIR/DB_OH_ohregistry.sh register name=$L_New_Name echo echo echo "Creating the new Golden Image $L_New_Name" echo # Copy to NFS working copy echo "Cleaning previous working copy" WC=$WORKING_COPY_DEST/$L_New_Name [ -d $WC ] && rm -rf $WC echo "Copying the OH to the working copy" mkdir -p $WC cp -rp $ORACLE_HOME/* $WC/ 2>/tmp/ohctl.err # Cleanup files echo "Cleansing files in Working Copy" rm -rf $WC/log/$HOSTNAME rm -rf $WC/log/diag/rdbms/* rm -rf $WC/gpnp/$HOSTNAME find $WC/gpnp -type f -exec rm {} \; 2>/dev/null rm -rf $WC/cfgtoollogs/* rm -rf $WC/crs/init/* rm -rf $WC/cdata/* rm -rf $WC/crf/* rm -rf $WC/admin/* rm -rf $WC/network/admin/*.ora rm -rf $WC/crs/install/crsconfig_params find $WC -name '*.ouibak' -exec rm {} \; 2>/dev/null find $WC -name '*.ouibak.1' -exec rm {} \; 2>/dev/null # rm -rf $WC/root.sh find $WC/rdbms/audit -name '*.aud' -exec rm {} \; 2>/dev/null rm -rf $WC/rdbms/log/* rm -rf $WC/inventory/backup/* rm -rf $WC/dbs/* # create zip echo "Creating the Golden Image zip file" [ -f $GOLDEN_IMAGE_DEST/$L_New_Name.zip ] && rm $GOLDEN_IMAGE_DEST/$L_New_Name.zip cd $WC zip -r $GOLDEN_IMAGE_DEST/$L_New_Name.zip . >/dev/null cd $OLDPWD # add image to OH_GOLDEN_IMAGES $SQLPLUS -S -L ${REPO_CREDENTIALS} <<EOF set feed off delete from oh_golden_images where name='${L_New_Name}'; insert into oh_golden_images (name, created, fullpath) values ( '${L_New_Name}', systimestamp, '$GOLDEN_IMAGE_DEST/$L_New_Name.zip'); commit; exit EOF fi if [ $L_Action == "remove" ] ; then echo "Remove" RESULT=`F_Image_Exists $L_Golden_Image` if [ "$RESULT" == "false" ] ; then echo "The image $L_Golden_Image does not exist" exit else echo "OK, the image exists." if [ "$L_GI_Overwrite" != "yes" ] ; then echo "Image $L_New_Name marked for delete but -f not specified. Exiting." exit 1 fi L_Image_Path=`echo "$RESULT" | awk -F\; '{print $3}'` [ -f "$L_Image_Path" ] && rm $L_Image_Path $SQLPLUS -S -L ${REPO_CREDENTIALS} <<EOF delete from oh_golden_images where name='${L_Golden_Image}'; commit; exit EOF exit fi fi |
The following two tabs change content below.
Latest posts by Ludovico (see all)
- New views in Oracle Data Guard 23c - January 3, 2024
- New in Data Guard 21c and 23c: Automatic preparation of the primary - December 22, 2023
- Does FLASHBACK QUERY work across incarnations or after a Data Guard failover? - December 13, 2023