Automated Patching database – 2

In my eariler post Automated Patching database, I automated the database patching process. But there is one bug in the post. See,

#########################

# Step 4. apply patches,

foreach patchnum in todo_staging.lst

system(“opatch apply -silent -ocmrf ocm.rsp $patchnum”); # How to define a ocm.rsp file, pls. check here.

# Step 5. Startup db and listener,

system(“lsnrctl start $ORACLE_SID”);

system(“dbstart”);

# Step 5. Apply post-install steps,

foreach patchnum in todo_staging.lst

foreach item in post_install.lst for patchnum

run the item listed in post_install.lst

#########################

For example, if in the todo list, it has 123, 456, 789 and all of them have post install steps. Supposed that 789 fails to apply due to conflict and the script halts due to that conflict. If ppl restart the script from there, the post install steps will be skipped for 123 & 456 as they are already in the inventory!

My enhancement,

from-


sub applypatches{

my $newerr = 0;

open (checklist, "$todo_patch_lst");

my @lines = "";

my $line = "";

@lines = <checklist>;

foreach $line (@lines) {

$line =~ s/^\s+|\s+$//g;

my ($patchnum) = split(/:/, $line);

$patchnum =~ s/^\s+|\s+$//g;

$patchdir = GetOSPath("$ENV{PATCH_TOP}/patch/$patchnum/$patchnum");

my $opatchcmd = GetOSPath("$ENV{DB_OH}/OPatch/opatch apply -silent -ocmrf $rsp_conf $patchdir");

$newerr =system("$opatchcmd");

if ($newerr ne 0){

print "can not apply $patchnum...\n";

exit(1);

} else {

print "apply $patchnum successfully ... \n";

}

}

close checklist ;

print "*** For more detailed log, go to $ENV{DB_OH}/cfgtoollogs/opatch ... *** \n";

}

to-


sub applypatches{

my $newerr = 0;

open (checklist, "$todo_patch_lst");

my @lines = "";

my $line = "";

@lines = <checklist>;

foreach $line (@lines) {

$line =~ s/^\s+|\s+$//g;

my ($patchnum) = split(/:/, $line);

$patchnum =~ s/^\s+|\s+$//g;

$patchdir = GetOSPath("$ENV{PATCH_TOP}/patch/$patchnum/$patchnum");

my $opatchcmd = GetOSPath("$ENV{DB_OH}/OPatch/opatch apply -silent -ocmrf $rsp_conf $patchdir");

$newerr =system("$opatchcmd");

while ($newerr ne 0){

print "Can not apply $patchnum...\n";

my $resume = GetOSPath("$ENV{PATCH_TOP}/RESUME");

while (!(-e $resume)) {

print "Refer to the log and fix the issue. After that run command 'touch $ENV{PATCH_TOP}/RESUME', the flow should continue to run in next 1 mintue automatically... \n";

print "Ensure that the db instance is down before you create the RESUME file... \n";

sleep 60;

}

$newerr =system("$opatchcmd");

unlink $resume ;

}

print "Apply $patchnum successfully ... \n";

}

close checklist ;

print "*** For more detailed log, go to $ENV{DB_OH}/cfgtoollogs/opatch ... *** \n";

}