2

How can I get Bacula to move the tape to the IO slot after it has ran a specific job?

I run daily backups with Bacula since a couple of days and I was wondering if I can do this kind of thing. I've already specified the UseVolumeOnce = yes directive in the configuration files, but now I want to know if I can make Bacula move the tape to slot 24 (I/O slot) when the job finishes.

Can bacula do this or do I need to script it? If I need to script it, do you have experience with that?

3 Answers 3

2

Without having the same environment to test with, I'm not certain this will work, but a script like this called via the RunAfterJob directive in bacula-dir.conf should work:

#!/bin/sh
#
echo "unmount <device-name>" | <bacula-path>/bconsole -c bconsole.conf

If you want to avoid calling external scripts, you might experiment with the AlwaysOpen, RequiresMount/MountCommand/UnmountCommand, and/or OfflineOnUnmount directives. All of these are in the Device resource of your Storage Daemon configuration.

Also, can you clarify why this is desirable for you? Perhaps there's a solution to the root problem we're overlooking.

1
  • I've found something similar on the web and I'm using it with success. It's not ejecting to the IO slot, but it's useable. The reason I want this is because a daily backup is only half a tape, but company policy requires a tape to leave the building every day.
    – Gert M
    Jun 1, 2009 at 20:32
2

I have set up an admin job called Eject that runs the following script at priority 1000, so it is executed once all of the backups are finished:

You could also run it as a "RunAfterJob" option for a specific job.

#!/bin/bash

MAXATTEMPTS=3
STORAGE=StorageName
DEVICE=/dev/sg3
CODE=0

OUT=`mktemp /tmp/XXXXXX`

###########################################################################
## Eject the tape from the drive and determine which slot it ended up in ##
###########################################################################
STATUS=1
ATTEMPT=0
while [ $STATUS -ne 0 ] && [ $ATTEMPT -lt $MAXATTEMPTS ]; do
  echo "umount Storage=$STORAGE"|/usr/sbin/bconsole >> $OUT
  if ( grep "Command Failed" $OUT > /dev/null ); then
    STATUS=1  
    echo "Command Failed!"
    rm $OUT
  else
    STATUS=0
    cat $OUT
  fi
  ATTEMPT=$(( $ATTEMPT + 1 ))
done
SLOT=`tac $OUT|grep -m1 3307|cut -d" " -f6|cut -d, -f1`  # Find the last occurrence of the success message only
rm $OUT

if [ "x$SLOT" = "x" ] || [ $STATUS -ne 0 ]; then
  echo "ERROR: Unable to unmount drive after $ATTEMPT attempts"
  exit 1
else
  echo "Slot $SLOT unloaded from Drive-0 "
fi

###########################################
## Move the ejected tape to the I/O slot ##
###########################################
STATUS=1
ATTEMPT=0
while [ $STATUS -ne 0 ] && [ $ATTEMPT -lt $MAXATTEMPTS ]; do
  /usr/sbin/mtx -f $DEVICE transfer $SLOT 24
  STATUS=$?
  ATTEMPT=$(( $ATTEMPT + 1 ))
done
if [ $STATUS -ne 0 ]; then
  echo "ERROR: Unable to move tape from slot $SLOT to I/O after $ATTEMPT attempts"
  CODE=2
else
  echo "Tape moved from slot $SLOT to I/O"
fi

#################################
## Ensure the DB is up to date ##
#################################
echo "update slots Storage=$STORAGE"|/usr/sbin/bconsole > /dev/null
if [ $CODE -ne 0 ]; then
  exit $CODE
fi
0

You do have to script it, but the combination of Bacula and a recent version of MTX makes this not too painful.

Take a look at the "Run Before Job" and "Run After Job" 'Job' parameters to call your the script you've written. We've tended to favor calling a script that runs a command into bconsole (through input redirection) to unmount your tape volume, and then call MTX to move the tape around.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .