系统管理指南:设备和文件系统

磁带备份 RCM 脚本示例

本示例说明如何使用 RCM 脚本执行磁带备份。

磁带备份 RCM 脚本的功能

磁带备份 RCM 脚本可执行以下步骤:

  1. 设置 RCM 命令的分发表。

  2. 调用与指定的 RCM 命令对应的分发例程,并对于未实现的 RCM 命令以状态 2 退出。

  3. 设置 scriptinfo 部分。


    rcm_script_func_info=Tape backup appl script for DR
  4. 通过在 stdout 中列显所有磁带机设备名称,在系统中注册所有磁带机。


    rcm_resource_name=/dev/rmt/$f

    如果出现错误,则该脚本将在 stdout 中列显错误信息。


    rcm_failure_reason=$errmsg
  5. 为磁带设备设置资源信息。


    rcm_resource_usage_info=Backup Tape Unit Number $unit
  6. 通过检查备份应用程序是否使用该设备,设置 preremove 信息。如果备份应用程序未使用该设备,则动态重新配置操作将继续进行。如果备份应用程序使用该设备,则该脚本将检查 RCM_ENV_FORCE。如果将 RCM_ENV_FORCE 设置为 FALSE,则该脚本将拒绝动态重新配置操作,并列显以下消息:


    rcm_failure_reason=tape backup in progress pid=...

    如果将 RCM_ENV_FORCE 设置为 TRUE,则将停止备份应用程序,重新配置操作则继续进行。

磁带备份重新配置方案的结果

以下是使用 cfgadm 命令移除不包含 RCM 脚本的磁带设备时的各种结果。

以下是使用 cfgadm 命令移除包含 RCM 脚本的磁带设备时的各种结果。

示例-磁带备份 RCM 脚本


#! /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);

            }

    }