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

📄 chg-zd-mtx.sh

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 SH
📖 第 1 页 / 共 3 页
字号:
	Log `_ 'EJECT    -> ejecting tape from %s' "$tape"`	get_loaded_info 	if [ $loadedslot -gt 0 ]; then		Log `_ 'EJECT    -> moving tape from drive %s to storage slot %s' "$driveslot" "$loadedslot"`		if [ $offline_before_unload -ne 0 ]; then                        Run try_eject_device $tape		fi		sleep $unloadpause		result=`Run $MTX unload $loadedslot $driveslot 2>&1`		status=$?		Log `_ '         -> status %s, result "%s"' "$status" "$result"`		mtx_status_valid=0		if [ $status -ne 0 ]; then			answer="$result"			code=2		else			answer="$rawtape"			code=0		fi	else		answer=`_ 'Drive was not loaded'`		code=1	fi	Exit $code "$loadedslot" "$answer"	return $?				# in case we are internal}#### Reset the robot back to the first slot.###reset() {	test -n "$DEBUG" && set -x	Log `_ 'RESET    -> loading tape from slot %s to drive %s (%s)' "$firstslot" "$driveslot" "$tape"`	# Call loadslot without doing it as an internal and let it finish	# things up.	loadslot $firstslot	# NOTREACHED	Exit 2 `_ '<none>'` `_ 'reset: should not get here'`	return $?				# in case we are internal}#### Unload the current tape (if necessary) and load a new one (unless# "advance").  If no tape is loaded, get the value of "current" from# $slotfile.###loadslot() {	test -n "$DEBUG" && set -x	if [ $# -lt 1 ]; then		Exit 2 `_ '<none>'` `_ 'Missing -slot argument'`		return $?			# in case we are internal	fi	whichslot=$1	Log `_ 'LOADSLOT -> load drive %s (%s) from slot %s' "$driveslot" "$tape" "$whichslot"`	numeric=`echo $whichslot | sed 's/[^0-9]//g'`	case $whichslot in	current|prev|next|advance)		find_slot=$currentslot		;;	first)		find_slot=$firstslot		;;	last)		find_slot=$lastslot		;;	$numeric)		find_slot=$numeric		;;	clean)		find_slot=$cleanslot		;;	*)		Exit 2 `_ '<none>'` `_ 'Illegal slot: "%s"' "$whichslot"`		return $?			# in case we are internal		;;	esac	# Find the requested slot in the slot list.  By loading the "set"	# command with multiple copies, we guarantee that if the slot is	# found, we can look both forward and backward without running	# off the end.	Putting $cleanslot at the end allows us to find	# that slot since it is not in $slot_list.	get_slot_list	set x $slot_list $slot_list $slot_list $cleanslot	shift					# get rid of the "x"	prev_slot=$1	shift	while [ $# -gt 0 ]; do		if [ $1 -eq $find_slot ]; then			break		fi		prev_slot=$1		shift	done	if [ $# -le 0 ]; then		Exit 2 \		     `_ '<none>'` \		     `_ 'Cannot find slot %s in slot list (%s)' "$find_slot " "$slot_list"`		return $?			# in case we are internal	fi	# Determine the slot to load.	case $whichslot in	next|advance)		shift		loadslot=$1		;;	prev)		loadslot=$prev_slot		;;	*)		loadslot=$find_slot	esac	# If the desired slot is already loaded, we are done.  Only update	# current slot if this is not the cleaning slot.	get_loaded_info	if [ $loadslot = $loadedslot ]; then		if [ $loadslot -ne $cleanslot ]; then			rm -f $slotfile			echo $loadslot > $slotfile		fi		Exit 0 "$loadedslot" "$rawtape"		return $?			# in case we are internal	fi	if [ $loadedslot -eq -2 ]; then		Exit 0 "$loadedslot" "$rawtape"		return $?			# in case we are internal        fi	# If we are loading the cleaning tape, bump the cleaning count	# and reset the access count.  Otherwise, bump the access count	# and see if it is time to do a cleaning.	if [ $loadslot = $cleanslot ]; then		rm -f $cleanfile $accessfile		expr $cleancount + 1 > $cleanfile		echo 0 > $accessfile	else		rm -f $accessfile		expr $accesscount + 1 > $accessfile		if [ $autoclean -ne 0 -a $accesscount -gt $autocleancount ]		then			internal_call=`expr $internal_call + 1`			loadslot clean > /dev/null 2>&1			status=$?			internal_call=`expr $internal_call - 1`			if [ $status -ne 0 ]; then				Exit $status "$loadslot" "$exit_answer"				return $?	# in case we are internal			fi			# Slot $cleanslot might contain an ordinary tape			# rather than a cleaning tape.  A cleaning tape			# *MIGHT* auto-eject; an ordinary tape does not.			# We therefore have to read the status again to			# check what actually happened.			mtx_status_valid=0			get_loaded_info		fi	fi	# Unload whatever tape is in the drive.	internal_call=`expr $internal_call + 1`	eject > /dev/null 2>&1	status=$?	internal_call=`expr $internal_call - 1`	if [ $status -gt 1 ]; then		Exit $status "$exit_slot" "$exit_answer"		return $?			# in case we are internal	fi	# If we were doing an "advance", we are done.	if [ $whichslot = advance ]; then		if [ $loadslot -ne $cleanslot ]; then			rm -f $slotfile			echo $loadslot > $slotfile		fi		Exit 0 "$loadslot" "/dev/null"		return $?			# in case we are internal	fi	# Load the tape, finally!	Log `_ "LOADSLOT -> loading tape from slot %s to drive %s (%s)" "$loadslot" "$driveslot" "$tape"`	result=`Run $MTX load $loadslot $driveslot 2>&1`	status=$?	Log `_ '         -> status %s, result "%s"' "$status" "$result"`	mtx_status_valid=0	if [ $status -ne 0 ]; then		Exit 2 "$loadslot" "$result"		return $?			# in case we are internal	fi	###	# Cleaning tapes never go "ready", so instead we just sit here	# for "long enough" (as determined empirically by the user),	# then return success.	###	if [ $loadslot -eq $cleanslot ]; then		Run sleep $cleancycle		Exit 0 "$loadslot" "$rawtape"		return $?			# in case we are internal	fi	###	# Wait for the drive to go online.	###	waittime=0	ready=0	sleep $initial_poll_delay	while [ $waittime -lt $max_drive_wait ]; do                amdevcheck_status $tape		if [ $? -eq 0 ]; then			ready=1			break		fi		sleep $poll_drive_ready		waittime=`expr $waittime + $poll_drive_ready`	done	if [ $ready -eq 0 ]; then		Exit 2 "$loadslot" `_ 'Drive not ready after %s seconds, rewind said "%s"' "$max_drive_wait" "$result"`		return $?			# in case we are internal	fi	if [ $loadslot -ne $cleanslot ]; then		rm -f $slotfile		echo $loadslot > $slotfile	fi	Exit 0 "$loadslot" "$rawtape"	return $?				# in case we are internal}#### Return information about how the changer is configured and the current# state of the robot.###info() {	test -n "$DEBUG" && set -x	get_loaded_info	get_slot_list	Log       `_ 'INFO     -> first slot: %s' "$firstslot"`	LogAppend `_ '         -> current slot: %s' "$currentslot"`	LogAppend `_ '         -> loaded slot: %s' "$loadedslot"`	LogAppend `_ '         -> last slot: %s' "$lastslot"`	LogAppend `_ '         -> slot list: %s' "$slot_list"`	LogAppend `_ '         -> can go backwards: 1'`	LogAppend `_ '         -> havereader: %s' "$havereader"`        ###	# Check if a barcode reader is configured or not.  If so, it	# passes the 4th item in the echo back to amtape signifying it	# can search based on barcodes.	###	reader=        if [ $havereader -eq 1 ]; then		reader=1        fi	if [ $currentslot -lt $firstslot -o $currentslot -gt $lastslot ]; then		currentslot=$firstslot		# what "current" will get	fi	numslots=`expr $lastslot - $firstslot + 1`	Exit 0 "$currentslot" "$numslots 1 $reader"	return $?				# in case we are internal}#### Read the labelfile and scan for a particular entry.###read_labelfile() {	labelfile_entry_found=0	labelfile_label=	labelfile_barcode=	lbl_search=$1	bc_search=$2	line=0	while read lbl bc junk; do		line=`expr $line + 1`		if [ -z "$lbl" -o -z "$bc" -o -n "$junk" ]; then			Log       `_ 'ERROR    -> Line %s malformed: %s %s %s' "$line" "$lbl" "$bc" "$junk"`			LogAppend `_ '         -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"`			Exit 2 \			     `_ '<none>'` \			     `_ 'Line %s malformed in %s: %s %s %s' "$line" "$labelfile" "$lbl" "$bc" "$junk"`			return $?		# in case we are internal		fi		if [ $lbl = "$lbl_search" -o $bc = "$bc_search" ]; then			if [ $labelfile_entry_found -ne 0 ]; then				Log       `_ 'ERROR    -> Duplicate entries: %s line %s' "$labelfile" "$line"`				LogAppend `_ '         -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"`				Exit 2 \				     `_ '<none>'` \				     `_ 'Duplicate entries: %s line %s' "$labelfile" "$line"`				return $?	# in case we are internal			fi			labelfile_entry_found=1			labelfile_label=$lbl			labelfile_barcode=$bc		fi	done}#### Adds the label and barcode for the currently loaded tape to the# barcode file.  Return an error if the database is messed up.###addlabel() {	test -n "$DEBUG" && set -x	if [ $# -lt 1 ]; then		Exit 2 `_ '<none>'` `_ 'Missing -label argument'`		return $?			# in case we are internal	fi        tapelabel=$1	if [ $havereader -eq 0 ]; then		Exit 2 `_ '<none>'` `_ 'Not configured with barcode reader'`		return $?			# in case we are internal	fi        get_loaded_info	if [ $loadedslot -lt 0 ]; then		Exit 1 `_ '<none>'` `_ 'No tape currently loaded'`		return $?			# in case we are internal	fi	if [ -z "$loadedbarcode" ]; then		Exit 1 `_ '<none>'` `_ 'No barcode found for tape %s.' $tapelabel`		return $?			# in case we are internal	fi	Log       `_ 'LABEL    -> Adding label "%s" with barcode "%s" for slot %s into %s' "$tapelabel" "$loadedbarcode" "$loadedslot" "$labelfile"`	read_labelfile "$tapelabel" "$loadedbarcode" < $labelfile	if [ $labelfile_entry_found -ne 0 ]; then		lf_val=		if [ "$labelfile_barcode" != "$loadedbarcode" ]; then			lf_type=label			lf_val=$tapelabel			val_type=barcode			old_val=$labelfile_barcode			new_val=$loadedbarcode		elif [ "$labelfile_label" != "$tapelabel" ]; then			lf_type=barcode			lf_val=$loadedbarcode			val_type=label			old_val=$labelfile_label			new_val=$tapelabel		fi		if [ -n "$lf_val" ]; then			LogAppend `_ 'ERROR    -> !!! Label database corrupted !!!'`			LogAppend `_ '         -> "%s" conflicts with new %s "%s" for %s "%s"' "$old_val" "$val_type" "$new_val" "$lf_type" "$lf_val"`			Exit 2 \			     `_ '<none>'` \			     `_ '%s: "%s" conflicts with new %s "%s" for %s "%s"' "$tapelabel" "$old_val" "$val_type" "$new_val" "$lf_type" "$lf_val"`			return $?		# in case we are internal		fi		LogAppend `_ "         -> already synced"`	else		echo "$tapelabel $loadedbarcode" >> $labelfile		LogAppend `_ '         -> appended %s entry: %s %s' "$labelfile" "$tapelabel" "$loadedbarcode"`	fi	Exit 0 "$loadedslot" "$rawtape"	return $?				# in case we are internal}#### Look for a label in the barcode file.  If found, locate the slot it's# in by looking for the barcode in the mtx output, then load that tape.###searchtape() {	test -n "$DEBUG" && set -x	if [ $# -lt 1 ]; then		Exit 2 `_ '<none>'` `_ 'Missing -search argument'`		return $?			# in case we are internal	fi        tapelabel=$1	if [ $havereader -eq 0 ]; then		Exit 2 `_ '<none>'` `_ 'Not configured with barcode reader'`		return $?			# in case we are internal	fi	Log `_ 'SEARCH   -> Hunting for label "%s"' "$tapelabel"`	read_labelfile "$tapelabel" "" < $labelfile	if [ $labelfile_entry_found -eq 0 ]; then		LogAppend `_ '         -> !!! label "%s" not found in %s !!!' "$tapelabel" "$labelfile"`		LogAppend `_ '         -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"`		Exit 2 \		     `_ '<none>'` \		     `_ '%s: label "%s" not found in %s' "$tapelabel" "$tapelabel" "$labelfile"`		return $?			# in case we are internal	fi	LogAppend `_ '         -> barcode is "%s"' "$labelfile_barcode"`	get_mtx_status	foundslot=`sed -n '/VolumeTag *= *'$labelfile_barcode' *$/			{	s/.*Storage Element \([0-9][0-9]*\).*/\1/p	q}' < $mtx_status`	LogAppend `_ '         -> foundslot is %s' "$foundslot"`	if [ -z "$foundslot" ]; then		LogAppend `_ 'ERROR    -> !!! Could not find slot for barcode "%s"!!!' "$labelfile_barcode"`		LogAppend `_ '         -> Remove %s and run "%s %s update"' "$labelfile" "$sbindir/amtape" "$config"`		Exit 2 \		     `_ '<none>'` \		     `_ 'barcode "%s" not found in mtx status output' "$labelfile_barcode"`		return $?			# in case we are internal	fi	# Call loadslot without doing it as an internal and let it finish	# things up.	loadslot $foundslot	# NOTREACHED	Exit 2 `_ '<none>'` `_ 'searchtape: should not get here'`	return $?				# in case we are internal}#### Program invocation begins here###if [ $# -lt 1 ]; then	Exit 2 `_ '<none>'` `_ 'Usage: %s -command args' "$myname"`ficmd=$1shiftcase "$cmd" in-slot)	loadslot "$@"	;;-info)	info "$@"	;;-reset)	reset "$@"	;;-eject)	eject "$@"	;;-label) 	addlabel "$@"	;;-search)	searchtape "$@"	;;-clean)	loadslot clean	;;*)	Exit 2 `_ '<none>'` `_ 'unknown option: %s' "$cmd"`	;;esacExit 2 `_ '<none>'` `_ '%s: should not get here' "$myname"`

⌨️ 快捷键说明

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