]> git.sur5r.net Git - bacula/bacula/commitdiff
Add locking-mtx-changer + more doc
authorKern Sibbald <kern@sibbald.com>
Mon, 7 Jun 2004 14:40:44 +0000 (14:40 +0000)
committerKern Sibbald <kern@sibbald.com>
Mon, 7 Jun 2004 14:40:44 +0000 (14:40 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1387 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/examples/autochangers/locking-mtx-changer [new file with mode: 0644]
bacula/scripts/mtx-changer.in
bacula/src/cats/drop_bacula_database.in
bacula/src/cats/drop_mysql_database.in
bacula/src/cats/drop_sqlite_database.in

diff --git a/bacula/examples/autochangers/locking-mtx-changer b/bacula/examples/autochangers/locking-mtx-changer
new file mode 100644 (file)
index 0000000..451a36d
--- /dev/null
@@ -0,0 +1,155 @@
+#!/bin/ksh
+#
+# Bacula interface to mtx autoloader
+#
+#  $Id$
+#
+#  If you set in your Device resource
+#
+#  Changer Command = "path-to-this-script/mtx-changer" %c %o %S %a %d
+#    you will have the following input to this script:
+#
+#  mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index"
+#                 $1              $2       $3        $4               $5
+#
+#  for example:
+#
+#  mtx-changer /dev/sg0 load 1 /dev/nst0 0 (on a Linux system)
+#
+#  If you need to an offline, refer to the drive as $4
+#    e.g.   mt -f $4 offline
+#
+#  Many changers need an offline after the unload. Also many
+#   changers need a sleep 60 after the mtx load.
+#
+#  N.B. If you change the script, take care to return either 
+#   the mtx exit code or a 0. If the script exits with a non-zero
+#   exit code, Bacula will assume the request failed.
+#
+
+MTX=/lysator/bin/mtx
+LOCKDIR=/tmp
+
+if test $# -lt 2 ; then
+  echo "usage: mtx-changer ctl-device command slot archive-device drive"
+  echo "  Insufficient number of arguments arguments given."
+  echo "  Mimimum usage is first two arguments ..."
+  exit 1
+fi
+
+# Setup arguments
+ctl=$1
+cmd="$2"
+slot=$3
+device=$4
+# If drive not given, default to 0
+if test $# = 5 ; then
+  drive=$5
+else
+  drive=0
+fi
+
+wait_for_drive() {
+    while ! mt -f $1 status >/dev/null 2>/dev/null; do
+#      echo "Device $1 - not ready, retrying..."
+       sleep 5
+    done
+}
+
+LOCKFILE="${LOCKDIR}/mtx-changer:`echo $ctl | tr / _'"
+
+changer_lock() {
+    echo "$$" >$LOCKFILE.$$
+    
+    while ! ln -n $LOCKFILE.$$ $LOCKFILE 2>/dev/null; do
+       echo "$0: changer lock busy, retrying in 30 seconds..."
+       sleep 30
+    done
+
+    rm $LOCKFILE.$$
+}
+
+changer_unlock() {
+    LOCKPID="`cat $LOCKFILE 2>/dev/null`"
+    if [ "$LOCKPID" != $$ ]; then
+       echo "$0: Invalid lock file (${LOCKFILE}) - not owned by us!"
+       exit 1
+    fi
+}
+
+
+
+#
+# Check for special cases where only 2 arguments are needed, 
+#  all others are a minimum of 3
+case $cmd in
+   loaded)
+     ;;
+   unload)
+     ;;
+   list)
+     ;;
+   slots)
+     ;;
+   *)
+     if test $# -lt 3; then
+       echo "usage: mtx-changer ctl-device command slot archive-device drive"
+       echo "  Insufficient number of arguments arguments given."
+       echo "  Mimimum usage is first three arguments ..."
+       exit 1
+     fi
+     ;;
+esac
+
+changer_lock $ctl
+
+case $cmd in 
+   unload)
+#     echo "Doing mtx -f $ctl unload $slot $drive"
+#
+# enable the following line if you need to eject the cartridge
+      mt -f $device offline
+      if test x$slot = x; then
+        ${MTX} -f $ctl unload
+        rtn=$?
+      else
+        ${MTX} -f $ctl unload $slot $drive
+        rtn=$?
+      fi
+      ;;
+
+   load)
+#     echo "Doing mtx -f $ctl load $slot $drive"
+      ${MTX} -f $ctl load $slot $drive
+      rtn=$?
+
+      wait_for_drive $device
+      changer_unlock $ctl
+      exit $rtn
+      ;;
+
+   list) 
+#     echo "Requested list"
+      ${MTX} -f $ctl status | tr ':=' '  ' | nawk '($1 == "Storage" && $2 == "Element" && $4 == "Full") { printf "%s:%s\n", $3, $6 }'
+      rtn=$?
+      ;;
+
+   loaded)
+      ${MTX} -f $ctl status >/tmp/mtx.$$
+      rtn=$?
+      cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
+      cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
+      rm -f /tmp/mtx.$$
+      changer_unlock $ctl
+      exit $rtn
+      ;;
+
+   slots)
+#     echo "Request slots"
+      ${MTX} -f $ctl status | grep " *Storage Changer" | awk "{print \$5}"
+      rtn=$?
+      ;;
+esac
+
+changer_unlock $ctl
+exit $rtn
index 17e57ec3aed923cb8c3008666ba10ab3fad35b8f..3760cae748cabe9ab6d82a183e4245c15f636e00 100644 (file)
@@ -97,6 +97,8 @@ case $cmd in
    list) 
 #     echo "Requested list"
       ${MTX} -f $ctl status | grep " *Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
+# Comment out the previous line and add a line here
+# to print "fake" barcodes.
       ;;
 
    loaded)
index cf9adc360de3db8be3af7d4594faa53759548873..cdc02fa4dbddd51994c7576162c27f4be6ae73ce 100755 (executable)
@@ -5,14 +5,11 @@
 #
 if test xsqlite = x@DB_NAME@ ; then
   @scriptdir@/drop_sqlite_database $*
-  echo "Dropped SQLite database"
 else
   if test xmysql = x@DB_NAME@ ; then 
     echo "Making MySQL database"
     @scriptdir@/drop_mysql_database $*
-    echo "Dropped MySQL database"
   else
     @scriptdir@/drop_postgresql_database $*
-    echo "Dropped PostgreSQL database"
   fi
 fi
index ff9ff481da45f04f9e16b35b0e03d0653f036243..aa447bc3bf6deaf65ee540c8ec718fe07316d2d0 100644 (file)
@@ -6,10 +6,10 @@
 bindir=@SQL_BINDIR@
 
 if test xmysql = x@DB_NAME@ ; then 
-  if $bindir/mysql $* -f <<END-OF-DATA
+  $bindir/mysql $* -f <<END-OF-DATA
     DROP DATABASE bacula;
-    END-OF-DATA
-  then
+END-OF-DATA
+  if test $? -eq 0 ; then
     echo "Drop of bacula database succeeded."
   else
     echo "Drop of bacula database failed."
index c937cdb88e9994b9a09e57bf8d3000e72b83e8d6..09913a6a400aaacf3fd9fb63e9a0abee6f11733f 100644 (file)
@@ -5,6 +5,7 @@
 if test xsqlite = x@DB_NAME@ ; then 
   cd @working_dir@
   rm -rf bacula.db
+  echo "SQLite database dropped."
 else
   echo "Bacula is not configured for an SQLite database."
 fi