I enjoy Bacula for automated home backups on DLT and DDS tape drives. Being used at home there’s no – obviously – big-dollar-company-manager to ask for an autoloader; and when the time of a tape change comes bacula lacks a simple way to request a manual tape change and just hangs up. So I managed to build a fake autoloader shell script, which, using emails, would emulate a real autoloader. This script, which I baptised mail-changer, features:

  • email support
  • periodic email resend when tape change is needed
  • tape detection and check (if you’re supposed to insert tape 4 and you enter 5, the script will kindly refuse the tape, unload it and send a warning email message asking for the right one)

To implement the third point (tape detection and check), it was necessary to extract the tape id from the bacula tape. That can be done looking at the bacula’s tape header structure:

The first structure stored is called “Block Header” and is 24 bytes long:

 uint32_t CheckSum; /* Block check sum */
 uint32_t BlockSize; /* Block byte size including the header */
 uint32_t BlockNumber; /* Block number */
 char ID[4] = "BB02"; /* Identification and block level */
 uint32_t VolSessionId; /* Session Id for Job */
 uint32_t VolSessionTime; /* Session Time for Job */

Then a “Record Header” follows (12 bytes):

 int32_t FileIndex; /* File index supplied by File daemon */
 int32_t Stream; /* Stream number supplied by File daemon */
 uint32_t DataSize; /* size of following data record in bytes */

Then a structure which is interesting for us, called “Volume Label” follows:

 char Id[32]; /* Bacula 1.0 Immortal\n */
 uint32_t VerNum; /* Label version number */
 /* VerNum 11 and greater Bacula 1.27 and later */
 btime_t label_btime; /* Time/date tape labeled */
 btime_t write_btime; /* Time/date tape first written */
 /* The following are 0 in VerNum 11 and greater */
 float64_t write_date; /* Date this label written */
 float64_t write_time; /* Time this label written */
 char VolName[128]; /* Volume name */ char PrevVolName[128];
 /* Previous Volume Name */
 char PoolName[128]; /* Pool name */
 char PoolType[128]; /* Pool type */
 char MediaType[128]; /* Type of this media */
 char HostName[128]; /* Host name of writing computer */
 char LabelProg[32]; /* Label program name */
 char ProgVersion[32]; /* Program version */
 char ProgDate[32]; /* Program build date/time */

What is really important for us is the VolName field, which is at relative offset +56 from the beginning of the Volume Label. Adding 12 bytes of Record Header and 24 of Block Header makes 92 bytes.

Please note that mail-changer has been developed on Solaris 10 using CSW’s Bacula, you may need to work a bit to adapt it to your unix.

You can download mail-changer here.