NAME

TapeChanger::MTX - use 'mtx' to manipulate a tape library


SYNOPSIS

  use TapeChanger::MTX;
  my $loaded = TapeChanger::MTX->loadedtape;
  print "Currently loaded: $loaded\n" if ($loaded);
  TapeChanger::MTX->loadtape('next');
  my $nowloaded = TapeChanger::MTX->loadedtape; 
  print "Currently loaded: $nowloaded\n" if ($nowloaded);
   
See below for more available functions.


DESCRIPTION

TapeChanger::MTX is a module to manipulate a tape library using the 'mtx' tape library program. It is meant to work with a simple shell/perl script to load and unload tapes as appropriate, and to provide a interface for more complicated programs to do the same. The below functions and variables should do as good a job as explaining this as anything.


VARIABLES

$TapeChanger::MTX::MT =item $TapeChanger::MTX::MTX
What is the location of the 'mt' and 'mtx' binaries? Can be set with '$MT' and '$MTX' in ~/.mtxrc, or defaults to '/usr/sbin/mt' and '/usr/local/sbin/mtx'.

$TapeChanger::MTX::DRIVE
$TapeChanger::MTX::CONTROL
What are the names of the tape (DRIVE) and changer (CONTROL) device nodes? Can be set with $DRIVE or $CONTROL in ~/.mtxrc, or default to '/dev/rmt/0' and '/dev/changer' respectively.

$TapeChanger::MTX::EJECT
Does the tape drive have to eject the tape before the changer retrieves it? It's okay to say 'yes' if it's not necessary, in most cases. Can be set with $EJECT in ~/.mtxrc, or defaults to '1'.

$TapeChanger::MTX::READY_TIME
How long should we wait to see if the drive is ready, in seconds, after mounting a volume? Can be set with $READY_TIME in ~/.mtxrc, or defaults to 60.

$TapeChanger::MTX::DEBUG
Print debugging information? Set to '0' for normal verbosity, '1' for debugging information, or '-1' for 'quiet mode' (be as quiet as possible).


USAGE

This module uses the following functions:

tape_cmd ( COMMAND )
mt_cmd ( COMMAND )
Runs 'mtx' and 'mt' as appropriate. COMMAND is the command you're trying to send to them. Uses 'warn()' to print the commands to the screen if $TapeChanger::MTX::DEBUG is set.

numdrives ()
numslots ()
loadedtape ()
Returns the number of drives, number of slots, and currently loaded tape values, respectively, by parsing tape_cmd('status').

loadtape ( SLOT [, DRIVE] )
Loads a tape into the tape changer, and waits until the drive is again ready to be written to. SLOT can be any of the following (with the relevant function indicated):
  current       C<loadedtape()>
  prev          C<loadprevtape()>
  next          C<loadnexttape()>
  first         C<loadfirsttape()>
  last          C<loadlasttape()>
  0             C<_ejectdrive()>
  1..99         Loads the specified tape number, ejecting whatever is
                currently in the drive.

DRIVE is the drive to load, and defaults to 0. Returns 0 if successful, an error string otherwise.

loadnexttape ()
loadprevtape ()
loadfirsttape ()
loadlasttape ()
Loads the next, previous, first, and last tapes in the changer respectively. Use tape_cmd('next'), tape_cmd('previous'), tape_cmd('first'), and tape_cmd('last'), respectively.

ejecttape ()
Ejects the tape, by first ejecting the tape from the drive (mt_cmd(rewind) then mt_cmd(offline)) and then returning it to its slot (tape_cmd(unload)). Returns 1 if successful, 0 otherwise.

resetchanger ()
Resets the changer, ejecting the tape and loading the first one from the changer.

checkdrive ()
Checks to see if the drive is ready or not, by waiting for up to $TapeChanger::MTX::READY_TIME seconds to see if it can get status information using mt_cmd(status). Returns 1 if so, 0 otherwise.

reportstatus
Returns a string containing the loaded tape and the drive that it's mounted on.

cannot_run ()
Does some quick checks to see if you're actually capable of using this module, based on your user permissions. Returns a list of problems if there are any, 0 otherwise.


NOTES

~/.mtxrc is automatically loaded when this module is used, if it exists, using do(). This could cause security problems if you're trying to use this with setuid() programs - so just don't do that. If you want someone to have permission to mess with the tape drive and/or changer, let them have that permission directly.


REQUIREMENTS

Perl 5.6.0 or better, an installed 'mtx' binary, and a tape changer and reader connected to the system.


TODO

Support for Input/Export slots is not included, though it may be later. Possibly works for multiple drives per changer, but I haven't tested it, so I probably missed something. 'load previous' doesn't actually work, because mtx doesn't support it (though the help says it does).


SEE ALSO

mtx, mt, tapechanger. Inspired by stc-changer, which comes with the AMANDA tape backup package (http://www.amanda.org), and MTX, available at http://mtx.sourceforge.net.


AUTHOR

Tim Skirvin <tskirvin@uiuc.edu>


COPYRIGHT

Copyright 2001-2002 by the University of Illinois Board of Trustees and Tim Skirvin <tskirvin@ks.uiuc.edu>.