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"
78 TAPE=`amgetconf tapedev`
79 if test X"$TAPE" = X""; then
80 echo `_ '<none> tapedev not specified in amanda.conf.'`
83 SLOTDIR=`echo $TAPE | sed 's/^file://'`
86 # should be exactly one arg
87 [ $# = 1 ] || return 1
88 # if arg is null, no expr needed
89 [ "${1}" = '' ] && return 1
90 # expr will return 0 on match
91 expr "$1" : '[0-9][0-9]*$' > /dev/null 2>&1
94 # Need rwx access to the virtual tape itself.
95 if ! test -d $SLOTDIR; then
96 echo `_ '<none> Virtual-tape directory %s does not exist.' "$SLOTDIR"`
99 if ! test -w $SLOTDIR; then
100 echo `_ '<none> Virtual-tape directory %s is not writable.' "$SLOTDIR"`
105 # need rwx access to directory of changer file
106 CHANGERFILE=`amgetconf changerfile`
107 conf_match=`expr "$CHANGERFILE" : .\*\.conf\$`
108 if [ $conf_match -ge 6 ]; then
109 CONFIGFILE=$CHANGERFILE
110 CHANGERFILE=`echo $CHANGERFILE | sed 's/.conf$//g'`
112 CONFIGFILE=$CHANGERFILE.conf
115 CFDir=`dirname ${CHANGERFILE}`
116 [ -d ${CFDir} -a -r ${CFDir} -a -w ${CFDir} -a -x ${CFDir} ] ||
117 { echo `_ "<none> %s: need 'rwx' access to '%s'" "$MYNAME" "$CFDir"` ; exit 2 ; }
119 # check or create changer metadata files
120 ACCESSFILE=$CHANGERFILE-access
121 [ -f $ACCESSFILE -a -r $ACCESSFILE -a -w $ACCESSFILE ] ||
122 echo 0 > $ACCESSFILE ||
123 { echo `_ "<none> %s: could not access or create '%s'" "$MYNAME" "$ACCESSFILE"` ; exit 2; }
124 CLEANFILE=$CHANGERFILE-clean
125 [ -f $CLEANFILE -a -r $CLEANFILE -a -w $CLEANFILE ] ||
126 echo 0 > $CLEANFILE ||
127 { echo `_ "<none> %s: could not access or create '%s'" "$MYNAME" "$CLEANFILE"` ; exit 2 ; }
128 SLOTFILE=$CHANGERFILE-slot
129 [ -f $SLOTFILE -a -r $SLOTFILE -a -w $SLOTFILE ] ||
130 echo 0 > $SLOTFILE ||
131 { echo `_ "<none> %s: could not access or create '%s'" "$MYNAME" "$SLOTFILE"` ; exit 2; }
133 # read and check metadata
134 ACCESSCOUNT=`cat $ACCESSFILE`
135 isinteger $ACCESSCOUNT || { ACCESSCOUNT=0 ; echo 0 > $ACCESSFILE ; }
136 CLEANCOUNT=`cat $CLEANFILE`
137 isinteger $CLEANCOUNT || { CLEANCOUNT=0 ; echo 0 > $CLEANFILE ; }
140 LASTSLOT=`amgetconf tapecycle`
141 if test -r $CONFIGFILE; then
146 NSLOT=`expr $LASTSLOT - $FIRSTSLOT + 1`
150 # unload should have been called, but just in case ...
151 [ -h $SLOTDIR/data ] && unload
152 ln -s $SLOTDIR/slot$WHICHSLOT $SLOTDIR/data
153 echo $WHICHSLOT > $SLOTFILE
162 CURSLOT=`cat $SLOTFILE`
168 TYPE=string # default if not numeric
169 isinteger $WHICHSLOT && TYPE=digit
173 if [ $WHICHSLOT = "current" ]; then
174 if [ $CURSLOT -le 0 ]; then
176 echo "$FIRSTSLOT $TAPE"
179 echo "$CURSLOT $TAPE"
182 elif [ $WHICHSLOT = "next" -o $WHICHSLOT = "advance" ]; then
183 NEWSLOT=`expr $CURSLOT + 1`
184 [ $NEWSLOT -gt $LASTSLOT ] && NEWSLOT=$FIRSTSLOT
185 elif [ $WHICHSLOT = "prev" ]; then
186 NEWSLOT=`expr $CURSLOT - 1`
187 [ $NEWSLOT -lt $FIRSTSLOT ] && NEWSLOT=$LASTSLOT
188 elif [ $WHICHSLOT = "first" ]; then
190 elif [ $WHICHSLOT = "last" ]; then
192 elif [ $TYPE = "digit" ]; then
193 if [ $WHICHSLOT -ge $FIRSTSLOT -a $WHICHSLOT -le $LASTSLOT ]; then
196 echo `_ '%s illegal slot' "$WHICHSLOT"`
199 elif [ $WHICHSLOT = "clean" ]; then
202 echo `_ '%s illegal request' "$WHICHSLOT"`
205 if [ $NEWSLOT = $CURSLOT ]; then
206 echo "$CURSLOT $TAPE"
209 if [ $NEWSLOT = $CLEANSLOT ]; then
210 expr ${CLEANCOUNT:=0} + 1 > $CLEANFILE
213 expr ${ACCESSCOUNT:=0} + 1 > $ACCESSFILE
214 if [ $ACCESSCOUNT -gt $LASTSLOT ]; then
215 $MYNAME -slot clean >/dev/null
220 if [ $CURSLOT -ne 0 ]; then
224 if [ $WHICHSLOT = "advance" ]; then
225 echo "$NEWSLOT /dev/null"
229 echo "$NEWSLOT $TAPE"
235 echo "$CURSLOT $NSLOT 1"
241 [ $CURSLOT -gt 0 ] && unload
243 echo "$FIRSTSLOT $tape"
249 if [ $CURSLOT -le 0 ]; then
250 echo `_ '0 Drive was not loaded'`
260 while [ $# -ge 1 ];do
307 echo `_ '<none> Unknown option %s' "$1"`