#!/usr/local/bin/perl # # $Header: rac_upgrade.pl 27-aug-2005.20:19:45 xuliu Exp $ # # rac_upgrade.pl # # Copyright (c) 2005, Oracle. All rights reserved. # # NAME # rac_upgrade.pl - upgrade cluster & host targets from 10.1 to 10.2 format # Usage: rac_upgrade.pl [-tgt_home] # # DESCRIPTION # # # NOTES # # # MODIFIED (MM/DD/YY) # xuliu 08/27/05 - xuliu_bug-4536783 # xuliu 08/17/05 - Creation # use strict; require "semd_common.pl"; my $tgtXmlPath = $ARGV[0]; if ( $tgtXmlPath eq "-tgt_home") { $tgtXmlPath = $ARGV[1]; } $tgtXmlPath = "${tgtXmlPath}/sysman/emd/targets.xml"; my ($sLns, $eLns, @tgts) = getTargets($tgtXmlPath); # Assumption: there is at most ONE host and ONE cluster target in the targets.xml my $hstIndex = -1; my $clsIndex = -1; for (my $i=0; $i<@tgts; $i++) { my $type = getTargetType($tgts[$i]); if ( uc($type) eq "CLUSTER") { $clsIndex = $i; last if ($hstIndex >= 0); } elsif (uc($type) eq "HOST") { $hstIndex = $i; last if ($clsIndex >= 0); } } my ($tmp, $crsHome) = getClusterName(); if ($clsIndex >= 0) { _DEBUG("CLUSTER target found as the " . $clsIndex . "th target: $tgts[$clsIndex]"); } else { _DEBUG("CLUSTER target NOT found."); } if ($hstIndex >= 0) { _DEBUG("HOST target found as the " . $hstIndex . "th target: $tgts[$hstIndex]"); } else { _DEBUG("HOST target NOT found."); } # proceed only if cluster and host targets exists if ($hstIndex >= 0 && $clsIndex >= 0) { my $clsName = getTargetName($tgts[$clsIndex]); my $OHProp = " \n"; _DEBUG("CLUSTER target name = $clsName"); _DEBUG("CRS_HOME = $crsHome"); if ($clsName ne "") { if ($crsHome ne "") { # add the OracleHome property to cluster target my $tgtCls = $tgts[$clsIndex]; $tgtCls =~ s/\n/ /g; my $trailTag = 1; if ($tgts[$clsIndex] =~ /\/>\s*$/) { _DEBUG("Cluster target ends with '/>'"); $trailTag = 0; } if (!$trailTag) { $tgts[$clsIndex] =~ s/\/>[\n\s]*$/>\n/s; $tgts[$clsIndex] .= " " . $OHProp; $tgts[$clsIndex] .= " \n"; } else { if ($tgtCls !~ //i) { $tgts[$clsIndex] =~ s/<\/Target/${OHProp} <\/Target/si; } else { _DEBUG("OracleHome property already exists for the cluster target...cluster target skipped: $&"); } } } else { _DEBUG("CRS_HOME is not found on the host...cluster target skipped."); } _DEBUG ("Upgraded cluster target=\n$tgts[$clsIndex]"); # now host target my $assoc = "\n "; my $tgtHst = $tgts[$hstIndex]; $tgtHst =~ s/\n/ /g; if ($tgtHst =~ //i) { my $mem = $1; if ( $mem =~ /NAME\s*=\s*\"${clsName}\"/i && $mem =~ /TYPE\s*=\s*\"cluster\"/i) { # let's see if the assoc already exists if ($tgtHst !~ //i) { $tgts[$hstIndex] =~ s/$tgtXmlPath") or die "Failed to open $tgtXmlPath for write\n"; print OUTFILE $sLns; for (my $i=0; $i<@tgts; $i++) { print OUTFILE $tgts[$i]; } print OUTFILE $eLns; close (OUTFILE); } else { _DEBUG("Cannot identify cluster target name"); } } sub getTargets { my $targetXml = $_[0]; my @rstTgts; my ($headLns, $tailLns); if (open(TGTXML, "<$targetXml")) { my @lns = ; close(TGTXML); my $bigL = join '', @lns; # get rid of comments $bigL =~ s///g; my @tgts = split //i) { $val = $1; } $val; } sub _DEBUG { print "INFO: $_[0]\n"; }