次の例では、テープのバックアップ用に RCM スクリプトを使用する方法を示します。
テープのバックアップ用 RCM スクリプトは、次の手順を実行します。
RCM コマンドのディスパッチテーブルをセットアップします。
指定した RCM コマンドに対応するディスパッチルーチンを呼び出し、実装されていない RCM コマンドについてはステータス 2 で終了します。
scriptinfo セクションをセットアップします。
rcm_script_func_info=Tape backup appl script for DR |
すべてのテープドライブデバイス名を stdout (標準出力) に出力して、システム内のすべてのテープドライブを登録します。
rcm_resource_name=/dev/rmt/$f |
rcm_failure_reason=$errmsg |
テープデバイスのリソース情報を設定します。
rcm_resource_usage_info=Backup Tape Unit Number $unit |
バックアップアプリケーションがそのデバイスを使用しているかどうかをチェックして、preremove 情報をセットアップします。バックアップアプリケーションがそのデバイスを使用していない場合は、動的再構成の操作はそのまま継続します。バックアップアプリケーションがそのデバイスを使用している場合は、スクリプトは RCM_ENV_FORCE をチェックします。RCM_ENV_FORCE が FALSE に設定されている場合は、スクリプトは動的再構成の操作を否定し、次のようなメッセージを出力します。
rcm_failure_reason=tape backup in progress pid=... |
RCM_ENV_FORCE が TRUE に設定されている場合は、バックアップアプリケーションが停止され、再構成の操作が進められます。
次に、RCM スクリプトを使用せずに、cfgadm コマンドを使用してテープデバイスを削除する場合に起こる結果を示します。
cfgadm コマンドを使用し、バックアップアプリケーションがテープデバイスを使用していない場合、操作は成功します。
cfgadm コマンドを使用し、バックアップアプリケーションがテープデバイスを使用している場合、操作は失敗します。
次に、RCM スクリプトを使用して、cfgadm コマンドを使用してテープデバイスを削除する場合に起こる結果を示します。
cfgadm コマンドを使用し、バックアップアプリケーションがテープデバイスを使用していない場合、操作は成功します。
-f オプション無しで cfgadm コマンドを使用し、バックアップアプリケーションがテープデバイスを使用している場合、操作は失敗し、次のようなエラーメッセージが出力されます。
tape backup in progress pid=... |
cfgadm -f コマンドを使用し、バックアップアプリケーションがテープデバイスを使用している場合、スクリプトがバックアップアプリケーションを停止させ、cfgadm 操作は成功します。
#! /usr/bin/perl -w
#
# A sample site customization RCM script.
#
# When RCM_ENV_FORCE is FALSE this script indicates to RCM that it cannot
# release the tape drive when the tape drive is being used for backup.
#
# When RCM_ENV_FORCE is TRUE this script allows DR removing a tape drive
# when the tape drive is being used for backup by killing the tape
# backup application.
#
use strict;
my ($cmd, %dispatch);
$cmd = shift(@ARGV);
# dispatch table for RCM commands
%dispatch = (
"scriptinfo" => \&do_scriptinfo,
"register" => \&do_register,
"resourceinfo" => \&do_resourceinfo,
"queryremove" => \&do_preremove,
"preremove" => \&do_preremove
);
if (defined($dispatch{$cmd})) {
&{$dispatch{$cmd}};
} else {
exit (2);
}
sub do_scriptinfo
{
print "rcm_script_version=1\n";
print "rcm_script_func_info=Tape backup appl script for DR\n";
exit (0);
}
sub do_register
{
my ($dir, $f, $errmsg);
$dir = opendir(RMT, "/dev/rmt");
if (!$dir) {
$errmsg = "Unable to open /dev/rmt directory: $!";
print "rcm_failure_reason=$errmsg\n";
exit (1);
}
while ($f = readdir(RMT)) {
# ignore hidden files and multiple names for the same device
if (($f !~ /^\./) && ($f =~ /^[0-9]+$/)) {
print "rcm_resource_name=/dev/rmt/$f\n";
}
}
closedir(RMT);
exit (0);
}
sub do_resourceinfo
{
my ($rsrc, $unit);
$rsrc = shift(@ARGV);
if ($rsrc =~ /^\/dev\/rmt\/([0-9]+)$/) {
$unit = $1;
print "rcm_resource_usage_info=Backup Tape Unit Number $unit\n";
exit (0);
} else {
print "rcm_failure_reason=Unknown tape device!\n";
exit (1);
}
}
sub do_preremove
{
my ($rsrc);
$rsrc = shift(@ARGV);
# check if backup application is using this resource
#if (the backup application is not running on $rsrc) {
# allow the DR to continue
# exit (0);
#}
#
# If RCM_ENV_FORCE is FALSE deny the operation.
# If RCM_ENV_FORCE is TRUE kill the backup application in order
# to allow the DR operation to proceed
#
if ($ENV{RCM_ENV_FORCE} eq 'TRUE') {
if ($cmd eq 'preremove') {
# kill the tape backup application
}
exit (0);
} else {
#
# indicate that the tape drive can not be released
# since the device is being used for backup by the
# tape backup application
#
print "rcm_failure_reason=tape backup in progress pid=...\n"
;
exit (3);
}
}
|