⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chg-zd-mtx.sh

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 SH
📖 第 1 页 / 共 3 页
字号:
#!@SHELL@ ## Exit Status:# 0 Alles Ok# 1 Illegal Request# 2 Fatal Error## Contributed by Eric DOUTRELEAU <Eric.Doutreleau@int-evry.fr># This is supposed to work with Zubkoff/Dandelion version of mtx## Modified by Joe Rhett <jrhett@isite.net># to work with MTX 1.2.9 by Eric Lee Green http://mtx.sourceforge.net## Modified by Jason Hollinden <jhollind@sammg.com> on 13-Feb-2001# to work with MTX 1.2.10, >9 slots, has barcode support, and works with# multiple configs at once.# NOTE:  Only tested the 2 additions with an ADIC Scalar 100.################################################################################# Here are the things you need to do and know to configure this script:##   * Figure out what the robot device name is and what the tape drive#     device name is.  They will be different!##     You cannot send robot commands to a tape drive and vice versa.#     Both should respond to "mtx -f /dev/... inquiry".  Hopefully,#     that output will make it obvious which is which.##     For instance, here is what mtx has to say about my current robot:##       Product Type: Medium Changer#       Vendor ID: 'ATL     '#       Product ID: 'ACL2640 206     '#       Revision: '2A5A'#       Attached Changer: No##     and here is what it says about a tape drive:##       Product Type: Tape Drive#       Vendor ID: 'Quantum '#       Product ID: 'DLT4000         '#       Revision: 'CD50'#       Attached Changer: No##     Note the "Product Type" value makes it clear which is which.##     If it is not obvious, "mf -f /dev/... rewind" should be happy when#     talking to a (loaded) tape drive but the changer should give some#     kind of error.  Similarly, "mtx -f /dev/... status" should show good#     results with the changer but fail with a tape drive device name.##     Once you have this figured out, set "changerdev" in amanda.conf#     to the changer device and "tapedev" to the tape device.##   * Find out what the first and last storage slots are.  Running#     "mtx -f /dev/... status" should give you something like this#     (although the output will vary widely based on the version of mtx#     and the specifics of your robot):##	  Storage Changer /dev/changer:1 Drives, 9 Slots ( 0 Import/Export )#	Data Transfer Element 0:Empty#	      Storage Element 1:Full :VolumeTag=SR0001#	      Storage Element 2:Full :VolumeTag=SR0002#	      Storage Element 3:Full :VolumeTag=SR0003#	      Storage Element 4:Full :VolumeTag=SR0004#	      Storage Element 5:Full :VolumeTag=SR0005#	      Storage Element 6:Full :VolumeTag=SR0006#	      Storage Element 7:Full :VolumeTag=SR0007#	      Storage Element 8:Full :VolumeTag=SR0008#	      Storage Element 9:Full :VolumeTag=SR0009#	      Storage Element 10 IMPORT/EXPORT:Full :VolumeTag=SR0009##     This says the first storage slot (element) is "1" and the last#     is "9".  If you allocate the entire robot to Amanda, you do not need#     to set the "firstslot" or "lastslot" configuration file variables --#     the script will compute these values for you.##     You do not have to allocate all of the slots for Amanda use,#     but whatever slots you use must be contiguous (i.e. 4 through 9#     in the above would be OK but 1, 2, 5, 6, 9 would not).  The one#     exception to this is that if one of the slots contains a cleaning#     cartridge, it may be in any slot (Amanda will just skip over it if#     it is between firstslot and lastslot).##   * Speaking of cleaning cartridges, if you have a storage slot dedicated#     to one, figure out what slot it is in.  That slot number will go in#     the "cleanslot" variable.##     Also, decide if you want the changer script to automatically run#     the cleaning tape through the drive after every so many mounts,#     and how many mounts you want to do between cleanings.  If you#     want the script to do this, set the "autoclean" variable to 1 and#     the "autocleancount" to the number of mounts between cleanings.#     If you do not want to do automatic cleanings (including not having#     a cleaning cartridge in the robot), set "autoclean" to 0.##     Note that only a count of mounts is used to determine when it is#     time to clean.  The script does not try to detect if the drive is#     requesting cleaning, or how much the drive was used on a given#     mount.##   * If you tell Amanda about a cleaning cartridge, whether for automatic#     operation or manual (amtape <config> clean), you must also tell#     the script how long it takes to run the cleaning cycle.  It is#     impossible for the script to determine when the cleaning operation#     is done, so the "cleancycle" variable is the number of seconds#     the longest cleaning operation takes (you'll just have to figure#     this out by watching it a few times, or maybe finding it in a tape#     drive hardware manual).  The script will sleep for this length of#     time whenever the cleaning tape is referenced.  The default is 120#     seconds (two minutes).##   * Figure out the drive slot number.  By default, it is set to 0.#     In the example above, the tape drive ("Data Transfer Element")#     is in slot 0. If your drive slot is not 0, you#     need to set the drive slot number with the "driveslot" variable.##   * Figure out whether your robot has a barcode reader and whether#     your version of mtx supports it.  If you see "VolumeTag" entries#     in the "mtx -f /dev/xxx status" output you did above, you have#     a reader and mtx can work with it, so you may set the "havereader"#     variable to 1.  The default is 0 (do not use a reader).##   * Pick any tape to load and then determine if the robot can put it#     away directly or whether an "offline" must be done first.##     With the tape still mounted and ready, try to put the tape away#     with "mtx".  If you get some kind of error, which is the most#     common response, try "mt -f /dev/... offline", wait for the drive#     to unload and make sure the robot takes no action on its own to#     store the tape.  Assuming it does not, try the "mtx" command again#     to store the tape.##     If you had to issue the "mt -f /dev/... offline" before you could#     use "mtx" to store the tape, set the "offline_before_unload"#     variable to 1.  If "mtx" unloaded the drive and put the tape away#     all by itself, set it to 0.##   * Some drives and robots require a small delay between unloading the#     tape and instructing the robot to move it back to storage.#     For instance, if you try to grab the tape too soon on an ATL robot#     with DLT tape drives, it will rip the leader out of the drive and#     require sincerely painful hardware maintenance.##     If you need a little delay, set the "unloadpause" variable to#     the number of seconds to wait before trying to take a tape from#     a drive back to storage.  The default is 0.##   * Some drives also require a short pause after loading, or the drive#     will return an I/O error during a test to see if it's online (which#     this script uses "mt rewind" to test).  My drives don't recover from#     this, and must be reloaded before they will come online after failing#     such a test.  For this reason there is an "initial_poll_delay"#     variable which will pause for a certain number of seconds before#     looping through the online test for the first time.  The default is 0.######### Now you are ready to set up the variables in the changer configuration# file.## All variables are in "changerfile".conf where "changerfile" is set# in amanda.conf.  For example, if amanda.conf has:##	changerfile="/etc/amanda/Dailyset1/CHANGER"#    or changerfile="/etc/amanda/Dailyset1/CHANGER.conf"## the variables must be in "/etc/amanda/Dailyset1/CHANGER.conf".# The ".conf" is appended only if it's not there".## If "changerfile" is a relative path, it is relative to the directory# that contains amanda.conf.  That also happens to be the directory Amanda# makes current before running this script.## Here is a commented out example file with all the variables and showing# their default value (if any):##### firstslot=?		    #### First storage slot (element) -- required# lastslot=?		    #### Last storage slot (element) -- required# cleanslot=-1		    #### Slot with cleaner tape -- default is "-1"#			    #### Set negative to indicate no cleaner available# driveslot=0		    #### Drive slot number.  Defaults to 0#			    #### Use the 'Data Transfer Element' you want##   # Do you want to clean the drive after a certain number of accesses?#   # NOTE - This is unreliable, since 'accesses' aren't 'uses', and we#   #        have no reliable way to count this.  A single amcheck could#   #        generate as many accesses as slots you have, plus 1.#   # ALSO NOTE - many modern tape loaders handle this automatically.## autoclean=0		    #### Set to '1' or greater to enable## autocleancount=99	    #### Number of access before a clean.## havereader=0		    #### If you have a barcode reader, set to 1.## offline_before_unload=0   #### Does your robot require an#			    #### 'mt offline' before mtx unload?## poll_drive_ready=NN	    #### Time (seconds) between tests to see if#			    #### the tape drive has gone ready (default: 3).## max_drive_wait=NN	    #### Maximum time (seconds) to wait for the#			    #### tape drive to become ready (default: 120).## initial_poll_delay=NN	    #### initial delay after load before polling for#			    #### readiness########## Now it is time to test the setup.  Do all of the following in the# directory that contains the amanda.conf file, and do all of it as# the Amanda user.##   * Run this:##       .../chg-zd-mtx -info#       echo $?             #### (or "echo $status" if you use csh/tcsh)##     You should get a single line from the script like this (the actual#     numbers will vary):##       5 9 1 1##     The first number (5) is the "current" slot.  This may or may not be#     the slot actually loaded at the moment (if any).  It is the slot#     Amanda will try to use next.##     The second number (9) is the number of slots.##     The third number will always be "1" and indicates the changer is#     capable of going backward.##     The fourth number is optional.  If you set $havereader to 1, it#     will be "1", otherwise it will not be present.##     The exit code ($? or $status) should be zero.##   * Run this:##       .../chg-zd-mtx -reset#       echo $?##     The script should output a line like this:##       1 /dev/rmt/0mn##     The number at the first should match $firstslot.  The device name#     after that should be your tape device.##     The exit code ($? or $status) should be zero.##   * Run this:##       .../chg-zd-mtx -slot next#       echo $?##     The script should output a line like this:##       2 /dev/rmt/0mn##     The number at the first should be one higher than $firstslot.#     The device name after that should be your tape device.##     The exit code ($? or $status) should be zero.##   * Run this:##       .../chg-zd-mtx -slot current#       echo $?##     Assuming the tape is still loaded from the previous test, the#     robot should not move and the script should report the same thing#     the previous command did.##   * If you continue to run "-slot next" commands, the robot should load#     each tape in turn then wrap back around to the first when it#     reaches $lasttape.  If $cleanslot is within the $firstslot to#     $lastslot range, the script will skip over that entry.##   * Finally, try some of the amtape commands and make sure they work:##       amtape <config> reset#       amtape <config> slot next#       amtape <config> slot current##   * If you set $havereader non-zero, now would be a good time to create#     the initial barcode database:##       amtape <config> update##################################################################################### To debug this script, first look in @AMANDA_DBGDIR@.  The script# uses one of two log files there, depending on what version of Amanda# is calling it.  It may be chg-zd-mtx.YYYYMMDD*.debug, or it may be# changer.debug.driveN where 'N' is the drive number.## If the log file does not help, try running the script, **as the Amanda# user**, in the amanda.conf directory with whatever set of args the log# said were used when you had a problem.  If nothing else useful shows up# in the output, try running the script with the DEBUG environment variable# set non-null, e.g.:##	env DEBUG=yes .../chg-zd-mtx ...################################################################################# source utility functions and values from configureprefix=@prefix@exec_prefix=@exec_prefix@amlibexecdir=@amlibexecdir@. ${amlibexecdir}/chg-lib.shtest -n "$DEBUG" && set -xTMPDIR="@AMANDA_TMPDIR@"DBGDIR="@AMANDA_DBGDIR@"argv0=$0myname=`expr "$argv0" : '.*/\(.*\)'`config=`pwd 2>/dev/null`config=`expr "$config" : '.*/\(.*\)'`#### Functions to write a new log file entry and append more log information.###ds=`date '+%H:%M:%S' 2>/dev/null`if [ $? -eq 0  -a  -n "$ds" ]; then	logprefix=`echo "$ds" | sed 's/./ /g'`else	logprefix=""fiLogAppend() {	if [ -z "$logprefix" ]; then		echo "$@" >> $DBGFILE	else		echo "$logprefix" "$@" >> $DBGFILE	fi}Log() {	if [ -z "$logprefix" ]; then		echo "===" "`date`" "===" >> $DBGFILE		echo "$@" >> $DBGFILE	else		ds=`date '+%H:%M:%S' 2>/dev/null`		echo "$ds" "$@" >> $DBGFILE	fi}#### Common exit function.##   $1 = exit code#   $2 = slot result#   $3 = additional information (error message, tape devive, etc)###internal_call=0Exit() {	if [ $internal_call -gt 0 ]; then		call_type=Return	else		call_type=Exit	fi	code=$1	shift	exit_slot=$1	shift	exit_answer="$@"	Log $call_type "($code) -> $exit_slot $@"	echo "$exit_slot" "$@"	if [ $call_type = Return ]; then		return $code	fi	amgetconf dbclose.$argv0:$DBGFILE > /dev/null 2>&1	exit $code}#### Function to run another command and log it.###Run() {	Log `_ 'Running: %s' "$@"`	rm -f $stdout $stderr	"$@" > $stdout 2> $stderr	exitcode=$?	Log `_ 'Exit code: %s' "$exitcode"`	if [ -s $stdout ]	then		LogAppend Stdout:		cat $stdout >> $DBGFILE	fi	if [ -s $stderr ]	then		LogAppend Stderr:		cat $stderr >> $DBGFILE	fi	cat $stdout	cat $stderr 1>&2	return $exitcode}#### Return success if the arg is numeric.###IsNumeric() {	test -z "$1" && return 1	x="`expr "$1" : '\([-0-9][0-9]*\)' 2>/dev/null`"	return `expr X"$1" != X"$x"`}#### Run $MTX status unless the previous output is still valid.###mtx_status_valid=0get_mtx_status() {	test -n "$DEBUG" && set -x	if [ $mtx_status_valid -ne 0 ]; then		return 0	fi	rm -f $mtx_status	Run $MTX status > $mtx_status 2>&1	status=$?	if [ $status -eq 0 ]; then		mtx_status_valid=1	fi	return $status}#### Determine the slot currently loaded.  Set $loadedslot to the slot# currently loaded, or "-1", and $loadedbarcode to the corresponding# barcode (or nothing).###get_loaded_info() {	test -n "$DEBUG" && set -x	get_mtx_status	set x `sed -n '/^Data Transfer Element:Empty/                          {    s/.*/-1/p    q}/^Data Transfer Element '$driveslot':Empty/             {    s/.*/-1/p    q}/^Data Transfer Element:Full (Storage Element \([0-9][0-9]*\) Loaded):VolumeTag *= *\([^     ]*\)/               {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -