User Tools

Site Tools


It would be nice if Bacula would warn you for faulty tapes, drive errors or when the tapedrive needs cleaning.
Bacula features the Alert command. Unfortunately there are some drawbacks:

  • Documentation is limited to the Bacula manual; there are no samples of it's usage
  • it does not work, well, at least in my setup it does not. Having a single slot tapedrive with automounting Bacula claims the drive so other programs are blocked due to a lock.
mt -f /dev/st0 status

is not always enough for some of us :-)
And has the same issue: device is locked.
TapeAlert is a feature which is supported by some tapedrives. Although described in the manual and found in many commented lines on the internet when Bacula related, there are some pitfalls:

  • your drive has to support this mechanism
  • a tape has to be physically present to be able to get the drive's status
  • the drive must not be locked(!). So beware of Bacula Storage Daemon!
  • after the status is read, the drive resets it's status(!!!), so rereading the status gives a different result!

Further information can be gathered from:

So, this feature is quite useful. However implementing it using the Alert command was not trivial. See also this posting on the mailinglist.

In my situation there is a single-slot tapedrive so tapes are manually switched/replaced. After the last backup and verify jobs have finished I run some admin-type jobs. One of them being:

Add smartcrl to your /etc/sudoers configuration as reading the tapedrive can be a bit tricky I used sudo for this purpose. :


#echo "release DDS-4" | /usr/bin/bconsole -c /etc/bacula/bconsole.conf
echo "unmount DDS-4" | /usr/bin/bconsole -c /etc/bacula/bconsole.conf

sleep 1m
sudo /usr/sbin/smartctl -a /dev/st0 -T verypermissive > /var/lib/bacula/tapeinfo.log

mt -f /dev/st0 rewind
mt -f /dev/st0 eject
sleep 2m

# mount an empty tapedrive
#   this will produce an error, but
#   will Bacula let take over control over the tapedrive again
echo "mount DDS-4" | /usr/bin/bconsole -c /etc/bacula/bconsole.conf


exit 0

Which takes care of:

  • unmounting the drive
  • as it is now unmounted I can finally get it's status! The status is stored in a logfile.
  • rewind & eject the tape
  • let the SD reclaim the drive (mount the drive regardless if a tape is inserted yet or not)

Within the script a logfile of the Tapedrive's status is created and an other script is called to process it. :

# OZ/04-09-2009


SUBJECT="Bacula tapedrive TapeInfo alert"

# script issued a: smartctl -a /dev/st0 > /var/lib/bacula/tapeinfo.log

# --- get email-address of Bacula's Tape-Operator & System Administrator ---

## get the first email-address of the Bacula Tape Operator(s)
bo=`cat $BACDIRCONF |sed -e 's/^[ \t]*//' | grep -w ^operator |cut -d"=" -f2 | head -1`
## get the first mail-address of the Bacula System Administrator(s)
bs=`cat $BACDIRCONF |sed -e 's/^[ \t]*//' | grep -w ^mail |cut -d"=" -f2 | head -1`

#echo "Email-address of Bacula's Tape-operator : $bo"
#echo "Email-address of Bacula's System Admin  : $bs"

# sanity check for email-addresses:
if [ ! -n "$bo" ]; then
  echo "Could not retrieve an email-address for the Bacula Tape-Operator."
  exit 1;
if [ ! -n "$bs" ]; then
  echo "Could not retrieve an email-address for the Bacula System Administrator."
  exit 1;

# sanity check for existence of the logfile
if [ ! -f $TAPEINFO_LOG ]; then
  echo "Could not find the logfile containing TapeInfo results."
  exit 1;

# now actually do what is intended to be done!
TA_OK=`cat $TAPEINFO_LOG | grep "TapeAlert: OK" -c`
if [ $TA_OK != "1" ]; then
  # hmm. TapeInfo is not OK. Send an email!
  $MAIL_BIN -s "$SUBJECT" -c "$bo" "$bs" < $TAPEINFO_LOG
tapealert.txt · Last modified: 2009/09/14 16:50 (external edit)