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 # changerdev "/dev/null"
47 # changerfile "chg-disk"
48 # tpchanger "chg-disk"
49 # changerfile "/usr/local/amanda/etc/changer"
51 # define tapetype HARD-DISK {
56 # Example changerfile (chg-disk.conf):
61 # The number of slot is equal to your LASTSLOT or tapecycle.
62 # You must create the slots and data directory.
67 exec_prefix="@exec_prefix@"
69 amlibexecdir="@amlibexecdir@"
70 . "${amlibexecdir}/amanda-sh-lib.sh"
72 # add sbin and ucb dirs
73 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
76 USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
77 if test "$USE_VERSION_SUFFIXES" = "yes"; then
85 TAPE=`amgetconf$SUF tapedev`
86 if test X"$TAPE" == X""; then
87 echo `_ '<none> tapedev not specified in amanda.conf.'`
90 SLOTDIR=`echo $TAPE | sed 's/^file://'`
93 # should be exactly one arg
94 [ $# = 1 ] || return 1
95 # if arg is null, no expr needed
96 [ "${1}" = '' ] && return 1
97 # expr will return 0 on match
98 expr "$1" : '[0-9][0-9]*$' > /dev/null 2>&1
101 # Need rwx access to the virtual tape itself.
102 if ! test -d $SLOTDIR; then
103 echo `_ '<none> Virtual-tape directory %s does not exist.' "$SLOTDIR"`
106 if ! test -w $SLOTDIR; then
107 echo `_ '<none> Virtual-tape directory %s is not writable.' "$SLOTDIR"`
112 # need rwx access to directory of changer file
113 CHANGERFILE=`amgetconf$SUF changerfile`
114 conf_match=`expr "$CHANGERFILE" : .\*\.conf\$`
115 if [ $conf_match -ge 6 ]; then
116 CONFIGFILE=$CHANGERFILE
117 CHANGERFILE=`echo $CHANGERFILE | sed 's/.conf$//g'`
119 CONFIGFILE=$CHANGERFILE.conf
122 CFDir=`dirname ${CHANGERFILE}`
123 [ -d ${CFDir} -a -r ${CFDir} -a -w ${CFDir} -a -x ${CFDir} ] ||
124 { echo `_ "<none> %s: need 'rwx' access to '%s'" "$MYNAME" "$CFDir"` ; exit 2 ; }
126 # check or create changer metadata files
127 ACCESSFILE=$CHANGERFILE-access
128 [ -f $ACCESSFILE -a -r $ACCESSFILE -a -w $ACCESSFILE ] ||
129 echo 0 > $ACCESSFILE ||
130 { echo `_ "<none> %s: could not access or create '%s'" "$MYNAME" "$ACCESSFILE"` ; exit 2; }
131 CLEANFILE=$CHANGERFILE-clean
132 [ -f $CLEANFILE -a -r $CLEANFILE -a -w $CLEANFILE ] ||
133 echo 0 > $CLEANFILE ||
134 { echo `_ "<none> %s: could not access or create '%s'" "$MYNAME" "$CLEANFILE"` ; exit 2 ; }
135 SLOTFILE=$CHANGERFILE-slot
136 [ -f $SLOTFILE -a -r $SLOTFILE -a -w $SLOTFILE ] ||
137 echo 0 > $SLOTFILE ||
138 { echo `_ "<none> %s: could not access or create '%s'" "$MYNAME" "$SLOTFILE"` ; exit 2; }
140 # read and check metadata
141 ACCESSCOUNT=`cat $ACCESSFILE`
142 isinteger $ACCESSCOUNT || { ACCESSCOUNT=0 ; echo 0 > $ACCESSFILE ; }
143 CLEANCOUNT=`cat $CLEANFILE`
144 isinteger $CLEANCOUNT || { CLEANCOUNT=0 ; echo 0 > $CLEANFILE ; }
147 LASTSLOT=`amgetconf$SUF tapecycle`
148 if test -r $CONFIGFILE; then
153 NSLOT=`expr $LASTSLOT - $FIRSTSLOT + 1`
157 # unload should have been called, but just in case ...
158 [ -h $SLOTDIR/data ] && unload
159 ln -s $SLOTDIR/slot$WHICHSLOT $SLOTDIR/data
160 echo $WHICHSLOT > $SLOTFILE
169 CURSLOT=`cat $SLOTFILE`
175 TYPE=string # default if not numeric
176 isinteger $WHICHSLOT && TYPE=digit
180 if [ $WHICHSLOT = "current" ]; then
181 if [ $CURSLOT -le 0 ]; then
183 echo "$FIRSTSLOT $TAPE"
186 echo "$CURSLOT $TAPE"
189 elif [ $WHICHSLOT = "next" -o $WHICHSLOT = "advance" ]; then
190 NEWSLOT=`expr $CURSLOT + 1`
191 [ $NEWSLOT -gt $LASTSLOT ] && NEWSLOT=$FIRSTSLOT
192 elif [ $WHICHSLOT = "prev" ]; then
193 NEWSLOT=`expr $CURSLOT - 1`
194 [ $NEWSLOT -lt $FIRSTSLOT ] && NEWSLOT=$LASTSLOT
195 elif [ $WHICHSLOT = "first" ]; then
197 elif [ $WHICHSLOT = "last" ]; then
199 elif [ $TYPE = "digit" ]; then
200 if [ $WHICHSLOT -ge $FIRSTSLOT -a $WHICHSLOT -le $LASTSLOT ]; then
203 echo `_ '%s illegal slot' "$WHICHSLOT"`
206 elif [ $WHICHSLOT = "clean" ]; then
209 echo `_ '%s illegal request' "$WHICHSLOT"`
212 if [ $NEWSLOT = $CURSLOT ]; then
213 echo "$CURSLOT $TAPE"
216 if [ $NEWSLOT = $CLEANSLOT ]; then
217 expr ${CLEANCOUNT:=0} + 1 > $CLEANFILE
220 expr ${ACCESSCOUNT:=0} + 1 > $ACCESSFILE
221 if [ $ACCESSCOUNT -gt $LASTSLOT ]; then
222 $MYNAME -slot clean >/dev/null
227 if [ $CURSLOT -ne 0 ]; then
231 if [ $WHICHSLOT = "advance" ]; then
232 echo "$NEWSLOT /dev/null"
236 echo "$NEWSLOT $TAPE"
242 echo "$CURSLOT $NSLOT 1"
248 [ $CURSLOT -gt 0 ] && unload
250 echo "$FIRSTSLOT $tape"
256 if [ $CURSLOT -le 0 ]; then
257 echo `_ '0 Drive was not loaded'`
267 while [ $# -ge 1 ];do
314 echo `_ '<none> Unknown option %s' "$1"`