Add a chio-changer script in replacement for the mtx-changer script.

Adapted from NetBSD pkgsrc and FreeBSD ports.
@sample the script so that people can apply local modifications if
needed.

Tested on an LTO-4, 8 slots.

Why do all chio(1) behave differently!!!???

ok sthen@ merdely@ (maintainer)
This commit is contained in:
ajacoutot 2012-06-28 19:24:56 +00:00
parent 2782c5366c
commit 587f3e6db4
5 changed files with 139 additions and 154 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.44 2012/06/16 07:08:55 robert Exp $
# $OpenBSD: Makefile,v 1.45 2012/06/28 19:24:56 ajacoutot Exp $
SHARED_ONLY= Yes
@ -7,8 +7,6 @@ COMMENT-server= network backup solution (server)
COMMENT-bat= network backup solution (gui-client)
V= 5.2.6
REVISION= 3
REVISION-server= 4
DISTNAME= bacula-$V
FULLPKGNAME-main= bacula-client-$V
FULLPKGPATH-main= ${PKGPATH},-main
@ -17,6 +15,10 @@ FULLPKGNAME-bat= bacula-bat-$V
FULLPKGPATH-bat= ${PKGPATH},-bat
CATEGORIES= sysutils
REVISION-main= 3
REVISION-server= 5
REVISION-bat= 3
# XXX build fails if a previous version is installed
SHARED_LIBS += bac 3.0
SHARED_LIBS += baccfg 3.0
@ -184,6 +186,8 @@ post-install:
.if ${BUILD_PACKAGES:M-server}
${INSTALL_SCRIPT_DIR} ${PREFIX}/libexec/bacula/updatedb
${INSTALL_SCRIPT} ${WRKSRC}/updatedb/* ${PREFIX}/libexec/bacula/updatedb
${SUBST_CMD} -o ${BINOWN} -g ${BINGRP} -c ${FILESDIR}/chio-changer \
${PREFIX}/libexec/bacula/chio-changer.dist
rm ${PREFIX}/libexec/bacula/updatedb/update*.in
rm ${PREFIX}/lib/libbaccats.*
cd ${PREFIX}/lib && \

View File

@ -0,0 +1,98 @@
#!/bin/sh
#
# $OpenBSD: chio-changer,v 1.1 2012/06/28 19:24:56 ajacoutot Exp $
#
# Bacula interface to chio autoloader
# (adapted from NetBSD pkgsrc and FreeBSD ports)
#
# If you set in your Device resource:
#
# Changer Command = "${TRUEPREFIX}/libexec/bacula/chio-changer %c %o %S %a %d"
# you will have the following input to this script:
#
# chio-changer "changer-device" "command" "slot" "archive-device" "drive-index"
# $1 $2 $3 $4 $5
#
# So Bacula will always call with all the following arguments, even though
# in come cases, not all are used.
#
# N.B. If you change the script, take care to return either
# the chio exit code or a 0. If the script exits with a non-zero
# exit code, Bacula will assume the request failed.
CHIO=/bin/chio
# check parameter count on commandline
check_parm_count() {
pCount=$1
pCountNeed=$2
if test $pCount -lt $pCountNeed; then
echo "usage: chio-changer ctl-device command [slot archive-device drive-index]"
echo " Insufficient number of arguments given."
if test $pCount -lt 2; then
echo " Mimimum usage is first two arguments ..."
else
echo " Command expected $pCountNeed arguments"
fi
exit 1
fi
}
# Check for special cases where only 2 arguments are needed,
# all others are a minimum of 5
case $2 in
list|listall)
check_parm_count $# 2
;;
slots)
check_parm_count $# 2
;;
transfer)
check_parm_count $# 4
;;
*)
check_parm_count $# 5
;;
esac
# Setup arguments
ctl=$1
cmd="$2"
slot=$3
device=$4
drive=$5
case $cmd in
unload)
${CHIO} -f $ctl move drive $drive slot $slot
;;
load)
${CHIO} -f $ctl move slot $slot drive $drive
;;
list)
${CHIO} -f $ctl status -v slot | \
sed -ne 's/^slot *\([0-9]*:\).*FULL.*voltag.*<\(.*\):.*/\1\2/p' | \
awk -F: '{print $1 + 1 ":" $2 }'
;;
listall)
echo "The listall command is not implemented on OpenBSD"
;;
loaded)
${CHIO} -f $ctl status -v | egrep "^drive $drive:" | grep FULL | cut -d: -f 3 | tr -d '<>a-z '
;;
slots)
${CHIO} -f $ctl params | awk "/slots/{print \$2}"
;;
transfer)
${CHIO} -f $ctl move slot $slot slot $device
;;
esac
sleep 1

View File

@ -1,143 +0,0 @@
$OpenBSD: patch-scripts_mtx-changer_in,v 1.7 2012/03/06 20:11:33 sthen Exp $
--- scripts/mtx-changer.in.orig Tue Feb 21 15:59:33 2012
+++ scripts/mtx-changer.in Mon Mar 5 12:43:07 2012
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# Bacula interface to mtx autoloader
+# Bacula interface to chio autoloader
#
# If you set in your Device resource
#
@@ -39,10 +39,10 @@
# 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.
+# changers need a sleep 60 after the chio 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
+# the chio exit code or a 0. If the script exits with a non-zero
# exit code, Bacula will assume the request failed.
#
@@ -175,7 +175,7 @@ debug "Parms: $ctl $cmd $slot $device $drive"
case $cmd in
unload)
- debug "Doing mtx -f $ctl unload $slot $drive"
+ debug "Doing chio -f $ctl move drive $drive slot $slot"
if test ${offline} -eq 1 ; then
mt -f $device offline
@@ -184,7 +184,7 @@ case $cmd in
sleep ${offline_sleep}
fi
make_err_file
- ${MTX} -f $ctl unload $slot $drive 2>${ERRFILE}
+ ${MTX} -f $ctl move slot $slot drive $drive 2>${ERRFILE}
rtn=$?
cat ${ERRFILE}
rm -f ${ERRFILE} >/dev/null 2>&1
@@ -194,7 +194,7 @@ case $cmd in
load)
debug "Doing mtx -f $ctl load $slot $drive"
make_err_file
- ${MTX} -f $ctl load $slot $drive 2>${ERRFILE}
+ ${MTX} -f $ctl slot $slot drive $drive 2>${ERRFILE}
rtn=$?
if test ${load_sleep} -ne 0 ; then
sleep ${load_sleep}
@@ -206,61 +206,21 @@ case $cmd in
;;
list)
- debug "Doing mtx -f $ctl -- to list volumes"
+ debug "Doing chio -f $ctl status -- to list volumes"
make_temp_file
if test ${inventory} -ne 0 ; then
${MTX} -f $ctl inventory
fi
${MTX} -f $ctl status >${TMPFILE}
- rtn=$?
- if test ${vxa_packetloader} -ne 0 ; then
- cat ${TMPFILE} | grep " *Storage Element [0-9]*:.*Full" | sed "s/ Storage Element //" | sed "s/Full :VolumeTag=//"
- else
- cat ${TMPFILE} | grep " Storage Element [0-9]*:.*Full" | awk "{print \$3 \$4}" | sed "s/Full *\(:VolumeTag=\)*//"
- fi
- cat ${TMPFILE} | grep "^Data Transfer Element [0-9]*:Full (Storage Element [0-9]" | awk '{printf "%s:%s\n",$7,$10}'
+ cat ${TMPFILE} | grep " *Storage Element [0-9]*:.*Full" | sed "s/ Storage Element //" | sed "s/Full :VolumeTag=//"
+ cat ${TMPFILE} | grep " *drive [0-9]*: <.*FULL.*>" | awk "{print \$2 \$4 \$5 \$6 \$7 \$8}" | sed "s/^/D/"
rm -f ${TMPFILE} >/dev/null 2>&1
exit $rtn
;;
listall)
-# Drive content: D:Drive num:F:Slot loaded:Volume Name
-# D:0:F:2:vol2 or D:Drive num:E
-# D:1:F:42:vol42
-# D:3:E
-#
-# Slot content:
-# S:1:F:vol1 S:Slot num:F:Volume Name
-# S:2:E or S:Slot num:E
-# S:3:F:vol4
-#
-# Import/Export tray slots:
-# I:10:F:vol10 I:Slot num:F:Volume Name
-# I:11:E or I:Slot num:E
-# I:12:F:vol40
-
- debug "Doing mtx -f $ctl -- to list all"
- make_temp_file
- if test ${inventory} -ne 0 ; then
- ${MTX} -f $ctl inventory
- fi
- ${MTX} -f $ctl status >${TMPFILE}
- rtn=$?
- # can be converted to awk+sed+cut, see below
- perl -ne '
-/Data Transfer Element (\d+):Empty/ && print "D:$1:E\n";
-/Data Transfer Element (\d+):Full \(Storage Element (\d+) Loaded\)(:VolumeTag =\s*(.+))?/ && print "D:$1:F:$2:$4\n";
-/Storage Element (\d+):Empty/ && print "S:$1:E\n";
-/Storage Element (\d+):Full( :VolumeTag=(.+))?/ && print "S:$1:F:$3\n";
-/Storage Element (\d+) IMPORT.EXPORT:Empty/ && print "I:$1:E\n";
-/Storage Element (\d+) IMPORT.EXPORT:Full( :VolumeTag=(.+))?/ && print "I:$1:F:$3\n";' ${TMPFILE}
- # If perl isn't installed, you can use by those commands
-#cat ${TMPFILE} | grep "Data Transfer Element" | awk "{print \"D:\"\$4 \$7 \$9 \$10}" | sed "s/=/:/" | sed "s/Full/F:/" | sed "s/Empty/E/"
-#cat ${TMPFILE} | grep -v "Data Transfer Element" | grep "Storage Element" | grep -v "IMPORT/EXPORT" | awk "{print \"S:\"\$3 \$4 \$5}" | sed "s/IMPORT\/EXPORT//" | sed "s/Full *:VolumeTag=/F:/" | sed "s/Empty/E/"
-#cat ${TMPFILE} | grep -v "Data Transfer Element" | grep "Storage Element" | grep "IMPORT/EXPORT" | awk "{print \"I:\"\$3 \$4 \$5}" | sed "s/IMPORT\/EXPORT//" | sed "s/Full *:VolumeTag=/F:/" | sed "s/Empty/E/"
-
- rm -f ${TMPFILE} >/dev/null 2>&1
- exit $rtn
+ echo "The listall command is not implemented on OpenBSD"
+ exit 1
;;
transfer)
@@ -272,18 +232,19 @@ case $cmd in
;;
loaded)
- debug "Doing mtx -f $ctl $drive -- to find what is loaded"
+ debug "Doing chio -f $ctl status -- to find what is loaded"
make_temp_file
${MTX} -f $ctl status >${TMPFILE}
rtn=$?
- cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
- cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
+ cat ${TMPFILE} | grep " *drive $drive: <.*FULL.*>" | awk "{print \$4}" | sed "s/^\[//" | sed "s/=\]$//"
+ cat ${TMPFILE} | grep " *drive $drive: <.*FULL.*>" > /dev/null 2>&1
+ if [ $? != 0 ]; then echo 0; fi
rm -f ${TMPFILE} >/dev/null 2>&1
exit $rtn
;;
slots)
- debug "Doing mtx -f $ctl -- to get count of slots"
- ${MTX} -f $ctl status | grep " *Storage Changer" | awk "{print \$5}"
+ debug "Doing chio -f $ctl status -- to get count of slots"
+ ${MTX} -f $ctl status | grep -c "slot [0-9]*"
;;
esac

View File

@ -1,11 +1,13 @@
$OpenBSD: patch-src_stored_bacula-sd_conf_in,v 1.3 2009/10/02 02:34:05 merdely Exp $
--- src/stored/bacula-sd.conf.in.orig Wed Jul 15 09:59:59 2009
+++ src/stored/bacula-sd.conf.in Tue Sep 1 22:34:25 2009
@@ -68,14 +68,14 @@ Device {
$OpenBSD: patch-src_stored_bacula-sd_conf_in,v 1.4 2012/06/28 19:24:56 ajacoutot Exp $
--- src/stored/bacula-sd.conf.in.orig Tue Feb 21 16:59:33 2012
+++ src/stored/bacula-sd.conf.in Thu Jun 28 19:53:06 2012
@@ -67,15 +67,15 @@ Device {
# Name = Autochanger
# Device = Drive-1
# Device = Drive-2
# Changer Command = "@scriptdir@/mtx-changer %c %o %S %a %d"
-# Changer Command = "@scriptdir@/mtx-changer %c %o %S %a %d"
-# Changer Device = /dev/sg0
+# Changer Command = "@scriptdir@/chio-changer %c %o %S %a %d"
+# Changer Device = /dev/ch0
#}
@ -27,15 +29,35 @@ $OpenBSD: patch-src_stored_bacula-sd_conf_in,v 1.3 2009/10/02 02:34:05 merdely E
# AutomaticMount = yes; # when device opened, read it
# AlwaysOpen = yes;
# RemovableMedia = yes;
@@ -122,7 +122,7 @@ Device {
@@ -121,8 +121,8 @@ Device {
# RemovableMedia = yes;
# RandomAccess = no;
# Maximum File Size = 3GB
## Changer Command = "@scriptdir@/mtx-changer %c %o %S %a %d"
-## Changer Command = "@scriptdir@/mtx-changer %c %o %S %a %d"
-## Changer Device = /dev/sg0
+## Changer Command = "@scriptdir@/chio-changer %c %o %S %a %d"
+## Changer Device = /dev/ch0
## AutoChanger = yes
# # Enable the Alert command only if you have the mtx package loaded
## Alert Command = "sh -c 'tapeinfo -f %c |grep TapeAlert|cat'"
@@ -142,7 +142,7 @@ Device {
# RemovableMedia = yes;
# RandomAccess = no;
# Maximum File Size = 4GB
-## Changer Command = "@scriptdir@/mtx-changer %c %o %S %a %d"
+## Changer Command = "@scriptdir@/chio-changer %c %o %S %a %d"
## Changer Device = /dev/sg0
## AutoChanger = yes
# # Enable the Alert command only if you have the mtx package loaded
@@ -163,7 +163,7 @@ Device {
# RemovableMedia = yes;
# RandomAccess = no;
# Maximum File Size = 5GB
-## Changer Command = "@scriptdir@/mtx-changer %c %o %S %a %d"
+## Changer Command = "@scriptdir@/chio-changer %c %o %S %a %d"
## Changer Device = /dev/sg0
## AutoChanger = yes
# # Enable the Alert command only if you have the mtx package loaded
@@ -182,7 +182,7 @@ Device {
# Name = DDS-4
# Description = "DDS-4 for FreeBSD"

View File

@ -1,4 +1,4 @@
@comment $OpenBSD: PLIST-server,v 1.12 2012/04/04 21:30:56 merdely Exp $
@comment $OpenBSD: PLIST-server,v 1.13 2012/06/28 19:24:56 ajacoutot Exp $
@conflict bacula-<2.2.7
@conflict bacula-client-<5.2.6p2
@newuser _bacula-sd:599:_bacula:daemon:Bacula Storage Daemon:/nonexistent:/sbin/nologin
@ -16,6 +16,10 @@ libexec/bacula/bacula-ctl-sd
libexec/bacula/btraceback.dbx
libexec/bacula/btraceback.gdb
libexec/bacula/btraceback.mdb
libexec/bacula/chio-changer.dist
@mode 0755
@sample libexec/bacula/chio-changer
@mode
libexec/bacula/create_bacula_database
libexec/bacula/create_${BACKEND}_database
libexec/bacula/delete_catalog_backup