#
# Written by Kern Sibbald
#
-# Bacula® - The Network Backup Solution
+# Bacula(R) - The Network Backup Solution
#
-# Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
+# Copyright (C) 2000-2016 Kern Sibbald
#
-# The main author of Bacula is Kern Sibbald, with contributions from many
-# others, a complete list can be found in the file AUTHORS.
+# The original author of Bacula is Kern Sibbald, with contributions
+# from many others, a complete list can be found in the file AUTHORS.
#
-# You may use this file and others of this release according to the
-# license defined in the LICENSE file, which includes the Affero General
-# Public License, v3.0 ("AGPLv3") and some additional permissions and
-# terms pursuant to its AGPLv3 Section 7.
-#
-# Bacula® is a registered trademark of Kern Sibbald.
+# You may use this file and others of this release according to the
+# license defined in the LICENSE file, which includes the Affero General
+# Public License, v3.0 ("AGPLv3") and some additional permissions and
+# terms pursuant to its AGPLv3 Section 7.
#
+# This notice must be preserved when any source code is
+# conveyed and/or propagated.
#
+# Bacula(R) is a registered trademark of Kern Sibbald.
# If you set in your Device resource
#
# Changer Command = "path-to-this-script/disk-changer %c %o %S %a %d"
# By default the autochanger has 10 Volumes and 1 Drive.
#
# Note: For this script to work, you *must" specify
-# Device Type = File
+# Device Type = File
# in each of the Devices associated with your AutoChanger resource.
#
# changer-device is the name of a file that overrides the default
# volumes and drives. It may have:
# maxslot=n where n is one based (default 10)
# maxdrive=m where m is zero based (default 1 -- i.e. 2 drives)
-#
+#
# This code can also simulate barcodes. You simply put
# a list of the slots and barcodes in the "base" directory/barcodes.
-# See below for the base directory definition. Example of a
+# See below for the base directory definition. Example of a
# barcodes file:
# /var/bacula/barcodes
# 1:Vol001
# 2:Vol002
# ...
-#
+#
# archive-device is the name of the base directory where you want the
# Volumes stored appended with /drive0 for the first drive; /drive1
# for the second drive, ... For example, you might use
# The Volumes will be created with names slot1, slot2, slot3, ... maxslot in the
# base directory. In the above example the base directory is /var/bacula.
# However, as with tapes, their Bacula Volume names will be stored inside the
-# Volume label. In addition to the Volumes (e.g. /var/bacula/slot1,
+# Volume label. In addition to the Volumes (e.g. /var/bacula/slot1,
# /var/bacula/slot3, ...) this script will create a /var/bacula/loadedn
# file to keep track of what Slot is loaded. You should not change this file.
#
maxslot=10
# Pull in conf file
-if [ -f $ctl ]; then
+if [ -f $ctl ]; then
. $ctl
fi
-# Check for special cases where only 2 arguments are needed,
+# Check for special cases where only 2 arguments are needed,
# all others are a minimum of 5
#
case $2 in
debug "Parms: $ctl $cmd $slot $device $drive $volume $havevol"
-case $cmd in
+case $cmd in
unload)
debug "Doing disk -f $ctl unload $slot $device $drive $volume"
get_dir
if [ -f $dir/loaded${drive} ]; then
ld=`cat $dir/loaded${drive}`
- else
+ else
echo "Storage Element $slot is Already Full"
debug "Unload error: $dir/loaded${drive} is already unloaded"
exit 1
if [ $slot -eq $ld ]; then
echo "0" >$dir/loaded${drive}
unlink $device 2>/dev/null >/dev/null
+ unlink ${device}.add 2>/dev/null >/dev/null
+ rm -f ${device} ${device}.add
else
echo "Storage Element $slot is Already Full"
debug "Unload error: $dir/loaded${drive} slot=$ld is already unloaded"
while [ $i -le $maxdrive ]; do
if [ -f $dir/loaded${i} ]; then
ld=`cat $dir/loaded${i}`
- else
+ else
ld=0
fi
if [ $ld -eq $slot ]; then
fi
echo "0" >$dir/loaded${drive}
unlink $device 2>/dev/null >/dev/null
+ unlink ${device}.add 2>/dev/null >/dev/null
+ rm -f ${device} ${device}.add
if [ $havevol -ne 0 ]; then
ln -s $dir/$volume $device
+ ln -s $dir/${volume}.add ${device}.add
rtn=$?
else
ln -s $dir/slot${slot} $device
+ ln -s $dir/slot${slot}.add ${device}.add
rtn=$?
fi
if [ $rtn -eq 0 ]; then
exit $rtn
;;
- list)
+ list)
debug "Doing disk -f $ctl -- to list volumes"
- get_dir
+ get_dir
if [ -f $dir/barcodes ]; then
cat $dir/barcodes
else
exit 0
;;
- listall)
+ listall)
# ***FIXME*** must add new Volume stuff
make_temp_file
debug "Doing disk -f $ctl -- to list volumes"
- get_dir
+ get_dir
if [ ! -f $dir/barcodes ]; then
exit 0
fi
# When we detect a gap, we print missing rows as empty
# At the end, we fill the gap between the last entry and maxslot
grep -v -f $TMPFILE $dir/barcodes | sort -n | \
- perl -ne 'BEGIN { $cur=1 }
+ perl -ne 'BEGIN { $cur=1 }
if (/(\d+):(.+)?/) {
- if ($cur == $1) {
- print "S:$1:F:$2\n"
- } else {
+ if ($cur == $1) {
+ print "S:$1:F:$2\n"
+ } else {
while ($cur < $1) {
print "S:$cur:E\n";
$cur++;
}
}
$cur++;
- }
+ }
END { while ($cur < '"$maxslot"') { print "S:$cur:E\n"; $cur++; } } '
rm -f $TMPFILE
echo "Transfering $slot to $slotdest"
mv $dir/slot${slot} $dir/slot{$slotdest}
+ mv $dir/slot${slot}.add $dir/slot{$slotdest}.add
if [ -f $dir/barcodes ]; then
sed "s/^$slot:/$slotdest:/" > $TMPFILE