3 # Bacula interface to virtual autoloader using disk storage
7 # If you set in your Device resource
9 # Changer Command = "path-to-this-script/disk-changer %c %o %S %a %d"
10 # you will have the following input to this script:
12 # So Bacula will always call with all the following arguments, even though
13 # in come cases, not all are used.
15 # disk-changer "changer-device" "command" "slot" "archive-device" "drive-index"
18 # By default the autochanger has 10 Volumes and 1 Drive.
20 # Note: For this script to work, you *must" specify
22 # in each of the Devices associated with your AutoChanger resource.
24 # changer-device is the name of a file that overrides the default
25 # volumes and drives. It may have:
26 # maxslot=n where n is one based (default 10)
27 # maxdrive=m where m is zero based (default 1 -- i.e. 2 drives)
29 # This code can also simulate barcodes. You simply put
30 # a list of the slots and barcodes in the "base" directory/barcodes.
31 # See below for the base directory definition. Example of a
33 # /var/bacula/barcodes
38 # archive-device is the name of the base directory where you want the
39 # Volumes stored appended with /drive0 for the first drive; /drive1
40 # for the second drive, ... For example, you might use
41 # /var/bacula/drive0 Note: you must not have a trailing slash, and
42 # the string (e.g. /drive0) must be unique, and it must not match
43 # any other part of the directory name. These restrictions could be
44 # easily removed by any clever script jockey.
46 # Full example: disk-changer /var/bacula/conf load 1 /var/bacula/drive0 0
48 # The Volumes will be created with names slot1, slot2, slot3, ... maxslot in the
49 # base directory. In the above example the base directory is /var/bacula.
50 # However, as with tapes, their Bacula Volume names will be stored inside the
51 # Volume label. In addition to the Volumes (e.g. /var/bacula/slot1,
52 # /var/bacula/slot3, ...) this script will create a /var/bacula/loadedn
53 # file to keep track of what Slot is loaded. You should not change this file.
62 # to turn on logging, uncomment the following line
63 #touch $wd/disk-changer.log
65 dbgfile="$wd/disk-changer.log"
67 if test -e $dbgfile; then
68 echo "`date +\"%Y%m%d-%H:%M:%S\"` $*" >> $dbgfile
74 # Create a temporary file
77 TMPFILE=`mktemp -t mtx.XXXXXXXXXX`
78 if test x${TMPFILE} = x; then
79 TMPFILE="$wd/disk-changer.$$"
80 if test -f ${TMPFILE}; then
81 echo "Temp file security problem on: ${TMPFILE}"
87 # check parameter count on commandline
92 if test $pCount -lt $pCountNeed; then
93 echo "usage: disk-changer ctl-device command [slot archive-device drive-index]"
94 echo " Insufficient number of arguments arguments given."
95 if test $pCount -lt 2; then
96 echo " Mimimum usage is first two arguments ..."
98 echo " Command expected $pCountNeed arguments"
105 # Strip off the final name in order to get the Directory ($dir)
106 # that we are dealing with.
109 bn=`basename $device`
110 dir=`echo "$device" | sed -e s%/$bn%%g`
111 if [ ! -d $dir ]; then
112 echo "ERROR: Autochanger directory \"$dir\" does not exist.\n"
113 echo " You must create it.\n"
136 # Check for special cases where only 2 arguments are needed,
137 # all others are a minimum of 5
141 check_parm_count $# 2
144 check_parm_count $# 2
147 check_parm_count $# 5
148 if [ $drive -gt $maxdrive ]; then
149 echo "Drive ($drive) out of range (0-$maxdrive)"
152 if [ $slot -gt $maxslot ]; then
153 echo "Slot ($slot) out of range (1-$maxslot)"
161 debug "Parms: $ctl $cmd $slot $device $drive"
165 debug "Doing disk -f $ctl unload $slot $device $drive"
167 echo "0" >$dir/loaded${drive}
168 unlink $device 2>/dev/null >/dev/null
173 debug "Doing disk $ctl load $slot $device $drive"
175 echo "0" >$dir/loaded${drive}
176 unlink $device 2>/dev/null >/dev/null
178 ln -s $dir/slot${slot} $device
180 if [ $rtn -eq 0 ]; then
181 echo $slot >$dir/loaded${drive}
187 debug "Doing disk -f $ctl -- to list volumes"
189 if [ -f $dir/barcodes ]; then
193 while [ $i -le $maxslot ]; do
202 debug "Doing disk -f $ctl $drive -- to find what is loaded"
204 if [ -f $dir/loaded${drive} ]; then
205 cat $dir/loaded${drive}
213 debug "Doing disk -f $ctl -- to get count of slots"