3 # Amanda, The Advanced Maryland Automatic Network Disk Archiver
4 # Copyright (c) 1991-1999 University of Maryland at College Park
7 # Permission to use, copy, modify, distribute, and sell this software and its
8 # documentation for any purpose is hereby granted without fee, provided that
9 # the above copyright notice appear in all copies and that both that
10 # copyright notice and this permission notice appear in supporting
11 # documentation, and that the name of U.M. not be used in advertising or
12 # publicity pertaining to distribution of the software without specific,
13 # written prior permission. U.M. makes no representations about the
14 # suitability of this software for any purpose. It is provided "as is"
15 # without express or implied warranty.
17 # U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 # Author: Jean-Christian SIMONETTI, System and Network Engineer
26 # Sophia Antipolis, France
28 # This changer script is based on a directory structure like:
36 # where 'slot_root_dir' is the tapedev 'file:xxx' parameter and 'n'
37 # is the tapecycle parameter.
39 # To use this driver, just put the line 'tpchanger "chg-disk"' in your
44 # tapedev "file:/BACKUP2/slots/"
45 # rawtapedev "file:/BACKUP2/slots/"
46 # changerdev "/dev/null"
47 # tpchanger "chg-disk"
48 # changerfile "/usr/local/amanda/etc/changer"
50 # define tapetype HARD-DISK {
55 # The number of slot is equal to your tapecyle.
56 # You must create the slots and data directory.
61 exec_prefix=@exec_prefix@
63 libexecdir=@libexecdir@
65 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:/usr/local/bin
68 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
69 if test "$USE_VERSION_SUFFIXES" = "yes"; then
77 TAPE=`amgetconf$SUF tapedev`
78 SLOTDIR=`echo $TAPE | sed 's/^file://'`
81 # should be exactly one arg
82 [ $# = 1 ] || return 1
83 # if arg is null, no expr needed
84 [ "${1}" = '' ] && return 1
85 # expr will return 0 on match
86 expr "$1" : '[0-9][0-9]*$' > /dev/null 2>&1
89 # Need rwx access to the virtual tape itself.
90 if ! test -d $SLOTDIR; then
91 echo "Virtual-tape directory $SLOTDIR does not exist." 1>&2
94 if ! test -w $SLOTDIR; then
95 echo "Virtual-tape directory $SLOTDIR is not writable." 1>&2
100 # need rwx access to directory of changer file
101 CHANGERFILE=`amgetconf$SUF changerfile`
102 CFDir=`dirname ${CHANGERFILE}`
103 [ -d ${CFDir} -a -r ${CFDir} -a -w ${CFDir} -a -x ${CFDir} ] ||
104 { echo "$MYNAME: need 'rwx' access to '$CFDir'" 1>&2 ; exit 2 ; }
106 # check or create changer metadata files
107 ACCESSFILE=$CHANGERFILE-access
108 [ -f $ACCESSFILE -a -r $ACCESSFILE -a -w $ACCESSFILE ] ||
109 echo 0 > $ACCESSFILE ||
110 { echo "$MYNAME: could not access or create '$ACCESSFILE'" 1>&2 ; exit 2 ; }
111 CLEANFILE=$CHANGERFILE-clean
112 [ -f $CLEANFILE -a -r $CLEANFILE -a -w $CLEANFILE ] ||
113 echo 0 > $CLEANFILE ||
114 { echo "$MYNAME: could not access or create '$CLEANFILE'" 1>&2 ; exit 2 ; }
115 SLOTFILE=$CHANGERFILE-slot
116 [ -f $SLOTFILE -a -r $SLOTFILE -a -w $SLOTFILE ] ||
117 echo 0 > $SLOTFILE ||
118 { echo "$MYNAME: could not access or create '$SLOTFILE'" 1>&2 ; exit 2 ; }
120 # read and check metadata
121 ACCESSCOUNT=`cat $ACCESSFILE`
122 isinteger $ACCESSCOUNT || { ACCESSCOUNT=0 ; echo 0 > $ACCESSFILE ; }
123 CLEANCOUNT=`cat $CLEANFILE`
124 isinteger $CLEANCOUNT || { CLEANCOUNT=0 ; echo 0 > $CLEANFILE ; }
127 LASTSLOT=`amgetconf$SUF tapecycle`
130 NSLOT=`expr $LASTSLOT - $FIRSTSLOT + 1`
134 # unload should have been called, but just in case ...
135 [ -h $SLOTDIR/data ] && unload
136 ln -s $SLOTDIR/slot$WHICHSLOT $SLOTDIR/data
137 echo $WHICHSLOT > $SLOTFILE
146 CURSLOT=`cat $SLOTFILE`
152 TYPE=string # default if not numeric
153 isinteger $WHICHSLOT && TYPE=digit
157 if [ $WHICHSLOT = "current" ]; then
158 if [ $CURSLOT -le 0 ]; then
160 echo "$FIRSTSLOT $TAPE"
163 echo "$CURSLOT $TAPE"
166 elif [ $WHICHSLOT = "next" -o $WHICHSLOT = "advance" ]; then
167 NEWSLOT=`expr $CURSLOT + 1`
168 [ $NEWSLOT -gt $LASTSLOT ] && NEWSLOT=$FIRSTSLOT
169 elif [ $WHICHSLOT = "prev" ]; then
170 NEWSLOT=`expr $CURSLOT - 1`
171 [ $NEWSLOT -lt $FIRSTSLOT ] && NEWSLOT=$LASTSLOT
172 elif [ $WHICHSLOT = "first" ]; then
174 elif [ $WHICHSLOT = "last" ]; then
176 elif [ $TYPE = "digit" ]; then
177 if [ $WHICHSLOT -ge $FIRSTSLOT -a $WHICHSLOT -le $LASTSLOT ]; then
180 echo "$WHICHSLOT illegal slot"
183 elif [ $WHICHSLOT = "clean" ]; then
186 echo "$WHICHSLOT illegal request"
189 if [ $NEWSLOT = $CURSLOT ]; then
190 echo "$CURSLOT $TAPE"
193 if [ $NEWSLOT = $CLEANSLOT ]; then
194 expr ${CLEANCOUNT:=0} + 1 > $CLEANFILE
197 expr ${ACCESSCOUNT:=0} + 1 > $ACCESSFILE
198 if [ $ACCESSCOUNT -gt $LASTSLOT ]; then
199 $MYNAME -slot clean >/dev/null
204 if [ $CURSLOT -ne 0 ]; then
208 if [ $WHICHSLOT = "advance" ]; then
209 echo "$NEWSLOT /dev/null"
213 echo "$NEWSLOT $TAPE"
219 echo "$CURSLOT $NSLOT 1"
225 [ $CURSLOT -gt 0 ] && unload
227 echo "$FIRSTSLOT $tape"
233 if [ $CURSLOT -le 0 ]; then
234 echo "0 Drive was not loaded"
244 while [ $# -ge 1 ];do
291 echo "Unknown option $1"