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 LASTSLOT value of your changerfile config file. If LASTSLOT is
38 # not defined, the value of the tapecycle parameter is used.
40 # To use this driver, just put the line 'tpchanger "chg-disk"' in your
43 # Example of use (amanda.conf):
45 # tapedev "file:/BACKUP2/slots/"
46 # rawtapedev "file:/BACKUP2/slots/"
47 # changerdev "/dev/null"
48 # changerfile "chg-disk"
49 # tpchanger "chg-disk"
50 # changerfile "/usr/local/amanda/etc/changer"
52 # define tapetype HARD-DISK {
57 # Example changerfile (chg-disk.conf):
62 # The number of slot is equal to your LASTSLOT or tapecycle.
63 # You must create the slots and data directory.
68 exec_prefix=@exec_prefix@
70 libexecdir=@libexecdir@
72 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:/usr/local/bin
75 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
76 if test "$USE_VERSION_SUFFIXES" = "yes"; then
84 TAPE=`amgetconf$SUF tapedev`
85 if test X"$TAPE" == X""; then
86 echo "<none> tapedev not specified in amanda.conf."
89 SLOTDIR=`echo $TAPE | sed 's/^file://'`
92 # should be exactly one arg
93 [ $# = 1 ] || return 1
94 # if arg is null, no expr needed
95 [ "${1}" = '' ] && return 1
96 # expr will return 0 on match
97 expr "$1" : '[0-9][0-9]*$' > /dev/null 2>&1
100 # Need rwx access to the virtual tape itself.
101 if ! test -d $SLOTDIR; then
102 echo "<none> Virtual-tape directory $SLOTDIR does not exist."
105 if ! test -w $SLOTDIR; then
106 echo "<none> Virtual-tape directory $SLOTDIR is not writable."
111 # need rwx access to directory of changer file
112 CHANGERFILE=`amgetconf$SUF changerfile`
113 conf_match=`expr "$CHANGERFILE" : .\*\.conf\$`
114 if [ $conf_match -ge 6 ]; then
115 CONFIGFILE=$CHANGERFILE
116 CHANGERFILE=`echo $CHANGERFILE | sed 's/.conf$//g'`
118 CONFIGFILE=$CHANGERFILE.conf
121 CFDir=`dirname ${CHANGERFILE}`
122 [ -d ${CFDir} -a -r ${CFDir} -a -w ${CFDir} -a -x ${CFDir} ] ||
123 { echo "<none> $MYNAME: need 'rwx' access to '$CFDir'"; exit 2 ; }
125 # check or create changer metadata files
126 ACCESSFILE=$CHANGERFILE-access
127 [ -f $ACCESSFILE -a -r $ACCESSFILE -a -w $ACCESSFILE ] ||
128 echo 0 > $ACCESSFILE ||
129 { echo "<none> $MYNAME: could not access or create '$ACCESSFILE'" ; exit 2 ; }
130 CLEANFILE=$CHANGERFILE-clean
131 [ -f $CLEANFILE -a -r $CLEANFILE -a -w $CLEANFILE ] ||
132 echo 0 > $CLEANFILE ||
133 { echo "<none> $MYNAME: could not access or create '$CLEANFILE'" ; exit 2 ; }
134 SLOTFILE=$CHANGERFILE-slot
135 [ -f $SLOTFILE -a -r $SLOTFILE -a -w $SLOTFILE ] ||
136 echo 0 > $SLOTFILE ||
137 { echo "<none> $MYNAME: could not access or create '$SLOTFILE'" ; exit 2 ; }
139 # read and check metadata
140 ACCESSCOUNT=`cat $ACCESSFILE`
141 isinteger $ACCESSCOUNT || { ACCESSCOUNT=0 ; echo 0 > $ACCESSFILE ; }
142 CLEANCOUNT=`cat $CLEANFILE`
143 isinteger $CLEANCOUNT || { CLEANCOUNT=0 ; echo 0 > $CLEANFILE ; }
146 LASTSLOT=`amgetconf$SUF tapecycle`
147 if test -r $CONFIGFILE; then
152 NSLOT=`expr $LASTSLOT - $FIRSTSLOT + 1`
156 # unload should have been called, but just in case ...
157 [ -h $SLOTDIR/data ] && unload
158 ln -s $SLOTDIR/slot$WHICHSLOT $SLOTDIR/data
159 echo $WHICHSLOT > $SLOTFILE
168 CURSLOT=`cat $SLOTFILE`
174 TYPE=string # default if not numeric
175 isinteger $WHICHSLOT && TYPE=digit
179 if [ $WHICHSLOT = "current" ]; then
180 if [ $CURSLOT -le 0 ]; then
182 echo "$FIRSTSLOT $TAPE"
185 echo "$CURSLOT $TAPE"
188 elif [ $WHICHSLOT = "next" -o $WHICHSLOT = "advance" ]; then
189 NEWSLOT=`expr $CURSLOT + 1`
190 [ $NEWSLOT -gt $LASTSLOT ] && NEWSLOT=$FIRSTSLOT
191 elif [ $WHICHSLOT = "prev" ]; then
192 NEWSLOT=`expr $CURSLOT - 1`
193 [ $NEWSLOT -lt $FIRSTSLOT ] && NEWSLOT=$LASTSLOT
194 elif [ $WHICHSLOT = "first" ]; then
196 elif [ $WHICHSLOT = "last" ]; then
198 elif [ $TYPE = "digit" ]; then
199 if [ $WHICHSLOT -ge $FIRSTSLOT -a $WHICHSLOT -le $LASTSLOT ]; then
202 echo "$WHICHSLOT illegal slot"
205 elif [ $WHICHSLOT = "clean" ]; then
208 echo "$WHICHSLOT illegal request"
211 if [ $NEWSLOT = $CURSLOT ]; then
212 echo "$CURSLOT $TAPE"
215 if [ $NEWSLOT = $CLEANSLOT ]; then
216 expr ${CLEANCOUNT:=0} + 1 > $CLEANFILE
219 expr ${ACCESSCOUNT:=0} + 1 > $ACCESSFILE
220 if [ $ACCESSCOUNT -gt $LASTSLOT ]; then
221 $MYNAME -slot clean >/dev/null
226 if [ $CURSLOT -ne 0 ]; then
230 if [ $WHICHSLOT = "advance" ]; then
231 echo "$NEWSLOT /dev/null"
235 echo "$NEWSLOT $TAPE"
241 echo "$CURSLOT $NSLOT 1"
247 [ $CURSLOT -gt 0 ] && unload
249 echo "$FIRSTSLOT $tape"
255 if [ $CURSLOT -le 0 ]; then
256 echo "0 Drive was not loaded"
266 while [ $# -ge 1 ];do
313 echo "<none> Unknown option $1"