Bacula Tape Changer (Autochanger) Library

Managed ad

By justin, 15 February, 2015

Sooo... I got an old Dell PowerVault-132T tape changer with a LTO-2 Drive. Actually I have 2 drives but 1 of them won't spin up so I am waiting on a part to make them both work, so for the purposes of this article I will do it with 1 drive and amend it later when I have the second drive fixed. I built this on Ubuntu 14.04 LTS

​This has made for a great series of articles! including:

History:

I originally was going to us Microsoft's System Center Data Protection Manager 2012 R2 (DPM) to do my backups, using a virtual machine so I added a the tape library to my SAN (see: Linux Fibre Channel SAN (Ubuntu)) then advertised it to the DPM VM using Synthetic Fiber Channel. it saw the changer and drive but windows 2008 R2 and Windows 2012 (R2) are lacking drivers for it. I also tried a PowerVault-122T which had built-in drivers but this was unreliable and the changer had issues issuing proper commands in this environment. as a result I gave up on that aproach and went to Bacula in a native linux environment on my SAN, but this posed other challenges such as the lack of a friendly GUI that supports Changers. Webmin does have a module for Bacula Backup System (by LinMin) but it lacks some features needed for a changer such as labeling tapes by barcodes, moving media from one slot to another, listing media and locations. Of course all of this can be done from the command line but it is always nice to have a interface. Also there was the issue of configuring Bacula for a Tape Changer that I had never done before. took some work but I figured it out. To my wife's displeasure it to 1 day to get Bacula up and running, performing backups  and another day to come up with a passible GUI using Webmin's Custom commands to fill in the blanks where the Bacula Backup System module left off. Then of course a 3rd day to do this write up.

Requirements:

  • Full (weekly) and incremental (6x week) backups of user files
  • Full backups of Hyper-V VMs
  • ​Move tapes from slot to slot
  • View tapes in slots
  • Label tapes by barcodes

Bacula Installation:

Throughout the installation process you will be prompted for information, but it is fairly straight forward if you are familiar with Linux.

Update your source repositories to make sure you get the latest version available:

sudo apt-get updateif you don't have MySQL installed, you will need it. you will also need to know the root password for it:

If you don't already have MySQL installed, you will need to install it (you will also need to know your root password for MySQL:

sudo apt-get install mysql-server

Now let's install the meat of Bacula

sudo apt-get install bacula-server bacula-client

Configuring Bacula for Tape Changer (Library):

When editing configuration files I normally use nano but use what you are familiar and comfortable with.

First edit the /etc/bacula/bacula-dir.conf file

sudo nano /etc/bacula/bacula-dir.conf

First near the start of the file you will see Director information. You will need to make note of the password. here is what you might see. the password is highlighted:

Director {                            # define myself
  Name = computer-dir
  DIRport = 9101                # where we listen for UA connections
  QueryFile = "/etc/bacula/scripts/query.sql"
  WorkingDirectory = "/var/lib/bacula"
  PidDirectory = "/var/run/bacula"
  Maximum Concurrent Jobs = 1
  Password = "gF6HGtyHG8756GtgR5G"         # Console password
  Messages = Daemon
  DirAddress = 127.0.0.1
}

We will need to add the storage information. To keep it orginized, there is a area where storage information for file storage is kept about 150-200 lines into the document. the storage devices will show up in the following format:

Storage {

yada...

yada...

}

in this area you will add the following sections:

Storage {

  Name = LTO-2-Device
  Address = localhost
  SDPort = 9103
  Password = "gF6HGtyHG8756GtgR5G"   #enter the console password noted above
  Device = LTO-2-0
  Media Type = LTO-2
  Autochanger = yes
  Maximum Concurrent Jobs = 5
}

Save the file and exit

Since the changer dev assignment for the changer can change at boot time, meaning that if this time it is /dev/sg8, next time you boot it may be /dev/sg4. therefore you need to have it set so it does not change. Mark Bergerman provided a nifty little script at: http://sourceforge.net/p/bacula/mailman/message/17432159/. This script makes a symbolic /dev/changer to the changer. I used nano to create a file called setchanger.sh then made it executable.

sudo nano ~/setchanger.sh

Now past the text of the script into the file. (Idon't know if he originally wrote it but it seems to work!). the script is:

#!  /bin/bash -x
# Shell script to create the /dev/changer symlink to the correct device. This is necessary
# because the /dev/sg* devices can (and do) change their targets upon reboot.

if [ -z $CREATECHANGERATTEMPTS  ] ; then
    CREATECHANGERATTEMPTS=0 
fi

if [ $CREATECHANGERATTEMPTS -gt 1 ] ; then
    echo "$0: error. Could not determine the /dev/sg\* device connected to the autochanger. /dev/changer not created."
    exit 1
else
    CREATECHANGERATTEMPTS=$((CREATECHANGERATTEMPTS + 1))
    export CREATECHANGERATTEMPTS

    if [ -e /dev/changer -a ! -h /dev/changer ]; then
        echo "$0: error. /dev/changer exists but is not a symlink"
        exit 1
    fi
    
    rm -f /dev/changer
    
    # Walk through the /dev/sg* devices, running the mtx command. Upon success, create
    # the link
    
    for device in /dev/sg*
    do
        mtx -f $device status 1> /dev/null 2>&1
        # mtx -f $device status 1> /tmp/create_changer.out 2> /dev/create_changer.errs
        if [ $? = 0 ] ; then
            ln -s $device /dev/changer
            exit 0
        fi
    done

    # We can only get here if the attempt failed...in that case...try:
    #
    #    force the HBA to rescan the devices
    #
    #    adding any devices that aren't registered with the OS
    #
    #    do a SCSI reset on those devices

    # Collect the initial sg_map, so that we can determine any new devices
    sgmapBEFORE=`sg_map | cut -f1 -d" "`

    # Find the correct host number for the HBA:
    hostnum=`cd /proc/scsi/qla2300; ls [0-9]*`
    bus=0

    # force a rescan
    echo "scsi-qlascan" > /proc/scsi/qla2300/$hostnum

    # Find all the devices that are not registered with the OS:
    grep "\*" /proc/scsi/qla2300/$hostnum | grep flags  | while read line
    do
        id=`echo $line | sed -e "s/:.*//" -e "s/.* //"`
        lun=`echo $line | sed -e "s/).*//" -e "s/.* //"`
        echo "scsi add-single-device $hostnum $bus $id $lun " > /proc/scsi/scsi
    done

    sgmapAFTER=`sg_map | cut -f1 -d" "`

    sgmapADDL=`echo $sgmapBEFORE $sgmapAFTER | tr " " "\012" | sort | uniq -u`

    if [ -z $sgmapADDL ] ; then
        echo "No new /dev/sg devices created"
        exit 1
    fi

    for dev in $sgmapADDL
    do
        sg_reset $dev
    done

    # Now, re-run this script
    $0
fi

Now make the script executible and execute it:

sudo chmod +x ~/setchanger.sh

sudo sh  ~/setchanger.sh

Now we need to edit the /etc/bacula/bacula-sd.conf file:

nano /etc/bacula/bacula-sd.conf

At the beginning you will find a storage section such as:

Storage {                             # definition of myself
  Name = computer-sd
  SDPort = 9103                  # Director's port
  WorkingDirectory = "/var/lib/bacula"
  Pid Directory = "/var/run/bacula"
  Maximum Concurrent Jobs = 20
  SDAddress = 127.0.0.1
}

after that section you will have to enter the info on your changer and drive:

Autochanger {
  Name = "PowerVault 132T"
  Device = LTO-2-0
  Changer Device = /dev/changer
  Changer Command = "/etc/bacula/scripts/mtx-changer %c %o %S %a %d"
}

Device {
  Name = LTO-2-0
  Drive Index = 0
  Autochanger = yes
  Archive Device = /dev/nst0
  Maximum Changer Wait = 3d
  AutomaticMount = yes
  AlwaysOpen = yes
  Media Type = LTO-2
  RemovableMedia = yes
  Offline On Unmount = no
  Spool Directory = /home/bacula/spool
  LabelMedia = yes
}

Now we have the basic install done and we can move on to the making it useable.

GUI in Webmin:

You will need to have webmin installed. if you don't have it installed, instructions for instakkubg ut from the APT repository (apt-get) can be found: http://www.webmin.com/deb.html

First we need a few scripts:

  • Media Information Custom Command: /etc/bacula/scripts/bconsolescriptList.sh  - This script lists all the media in the changer and where it is located (which slot), pool it is a member of, last written information, number of Bytes on the volume, number of files, etc...
  • Label by Barcodes: /etc/bacula/scripts/bconsolescriptbarcodelabel.sh  - Reads the barcodes and labels new tapes and puts them in the Scratch pool.
  • Move Media slot to slot Custom Command:
    • /etc/bacula/scripts/bconsoletestscriptMove.sh - This script will move the media from one slot to another.
    • /etc/bacula/scripts/bconsolscriptusedslotsoutput.sh - this populates the Source slot menu options.
    • /etc/bacula/scripts/bconsolscriptusedslots.sh - Which gets the information on the location of tapes in the system
    • /etc/bacula/scripts/bconsolescriptemptyslotsoutput.sh - this populates the Destination slot Menu options.
    • /etc/bacula/scripts/bconsolescriptList.sh - Updates the changer
  • slot information Custom Command: 
    • /etc/bacula/scripts/bconsolscriptusedslotsoutputForUser.sh - this script tells you what tape is in which slot.
    • /etc/bacula/scripts/bconsolscriptusedslots.sh - This is called by the bconsolscriptusedslotsoutputForUser.sh which runs the commands against the bconsole to get required information.

This scripts can be downloaded here: bconsoleCustomCommandsScripts.tar.gz. extract it and copy all of the .sh files in the custom folder to the /etc/bacula/scripts folder. I will also post the script text in this article to explain them.

Creating Custom Command:

Creating custom commands is pretty easy and it give you the ability to run scripts that you (or someone else) have written to perform repetitive tasks. 

  1. To create the custom command, log into webmin web interface and go to: Others-->Custom Commands.

     

  2. at the top of the page, click on the 'Create a new custom command' link

     

  3. The custom command form has the Command details and the Parameters. When you initially open it, you only have space for 1 parameter, but if you enter a parameter and create the command, when you go back and edit it, it will have a second one there, so each time you want to add a new parameter you will need to save it. you can use paramaters in your command line by using it in the form of <command> $<paramater>.

Media Information Custom Command:

This custom command queries and tells you the latest information from the tape library on the tapes, where they are, last write time, etc...

  1. create a custom command as explained in "Creating Custom Commands"
    1. give it the Description "Media Information"
    2. use the command: sh /etc/bacula/scripts/bconsolescriptList.sh 
    3. Leave everything else at the defaults. you also do not need any parameters.
    4. Click Save (or Create).
  2. Now test it:
    1. Go back to the Custom Commands and click Media Information

       
    2. Your output should be something like 

Output from sh /etc/bacula/scripts/bconsolescriptList.sh ..

Connecting to Director localhost:9101 1000 OK: computer-dir Version: 5.2.6 (21 February 2012) Enter a period to cancel a command. update Automatically selected Catalog: MyCatalog Using Catalog "MyCatalog" Update choice: 1: Volume parameters 2: Pool from resource 3: Slots from autochanger 4: Long term statistics Choose catalog item to update (1-4): 3 The defined Storage resources are: 1: File 2: LTO-2-0 Select Storage resource (1-2): 2 Connecting to Storage daemon LTO-2-0 at localhost:9103 ... 3306 Issuing autochanger "slots" command. Device "LTO-2-0" has 24 slots. Connecting to Storage daemon LTO-2-0 at localhost:9103 ... 3306 Issuing autochanger "list" command. Catalog record for Volume "000129" updated to reference slot 3. Catalog record for Volume "000159" updated to reference slot 5. Catalog record for Volume "000160" updated to reference slot 6. Catalog record for Volume "000161" updated to reference slot 8. Catalog record for Volume "000153" updated to reference slot 9. Catalog record for Volume "000154" updated to reference slot 10. Catalog record for Volume "000155" updated to reference slot 11. Catalog record for Volume "000137" updated to reference slot 13. Catalog record for Volume "000156" updated to reference slot 14. Catalog record for Volume "000157" updated to reference slot 15. Catalog record for Volume "000128" updated to reference slot 16. Catalog record for Volume "000162" updated to reference slot 17. Catalog record for Volume "000168" updated to reference slot 18. Catalog record for Volume "000018" updated to reference slot 19. Catalog record for Volume "000095" updated to reference slot 21. Catalog record for Volume "000158" updated to reference slot 22. Catalog record for Volume "000115" updated to reference slot 23. list media Pool: Default +---------+------------+-----------+---------+-----------------+----------+--------------+---------+------+-----------+-----------+---------------------+ | MediaId | VolumeName | VolStatus | Enabled | VolBytes | VolFiles | VolRetention | Recycle | Slot | InChanger | MediaType | LastWritten | +---------+------------+-----------+---------+-----------------+----------+--------------+---------+------+-----------+-----------+---------------------+ | 1 | 000129 | Full | 1 | 302,105,502,720 | 305 | 2,592,000 | 1 | 3 | 1 | LTO-2 | 2015-02-14 23:47:24 | | 2 | 000017 | Append | 1 | 456,343,437,312 | 458 | 2,592,000 | 1 | 0 | 0 | LTO-2 | 2015-02-15 04:09:16 | +---------+------------+-----------+---------+-----------------+----------+--------------+---------+------+-----------+-----------+---------------------+ Pool: File No results to list. Pool: Scratch +---------+------------+-----------+---------+----------+----------+--------------+---------+------+-----------+-----------+---------------------+ | MediaId | VolumeName | VolStatus | Enabled | VolBytes | VolFiles | VolRetention | Recycle | Slot | InChanger | MediaType | LastWritten | +---------+------------+-----------+---------+----------+----------+--------------+---------+------+-----------+-----------+---------------------+ | 3 | 000137 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 13 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 4 | 000095 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 21 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 5 | 000115 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 23 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 6 | 000018 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 19 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 7 | 000159 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 5 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 8 | 000160 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 6 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 9 | 000161 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 8 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 10 | 000153 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 9 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 11 | 000154 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 10 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 12 | 000155 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 11 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 13 | 000156 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 14 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 14 | 000157 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 15 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 15 | 000128 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 16 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 16 | 000162 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 17 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 17 | 000168 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 18 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 18 | 000158 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 22 | 1 | LTO-2 | 0000-00-00 00:00:00 | +---------+------------+-----------+---------+----------+----------+--------------+---------+------+-----------+-----------+---------------------+

There you go, it worked! For your information the /etc/bacula/scripts/bconsolescriptList.sh that we used here is very simple:

#Copyright disclaimer:
#    Copyright (C) 2015,  ITHierarchy Inc (www.ithierarchy.com). ALl rights reserverd.
#    This program is free software: you can redistribute it and/or modify
#        it under the terms of the GNU General Public License as published by
#        the Free Software Foundation, either version 3 of the License, or
#        (at your option) any later version.
#
#        This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty of
#        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#        GNU General Public License for more details.
#
#        You should have received a copy of the GNU General Public License
#        along with this program.  If not, see <http://www.gnu.org/licenses/>.

#!  /bin/bash

bconsole -c  /etc/bacula/bconsole.conf <<END_OF_DATA
update
3
2
list media
END_OF_DATA

Barcodes Label Custom Command:

If you have a barcode reader on your library, you normally want to label your tapes by barcode, that makes it easy to locate them.

  1. create a custom command as explained in "Creating Custom Commands"
    1. give it the Description "Barcode Label"
    2. use the command: sh /etc/bacula/scripts/bconsolescriptbarcodelabel.sh
    3. Leave everything else at the defaults. you also do not need any parameters.
    4. Click Save (or Create).
  2. Now test it:
    1. Go back to the Custom Commands and click Barcode Label

       
    2. You will get a lot of output should be (something) like this: (I trimmed it down to more relevant stuff) 

label barcodes Automatically selected Catalog: MyCatalog Using Catalog "MyCatalog" The defined Storage resources are: 1: File 2: LTO-2-0 Select Storage resource (1-2): 2 Connecting to Storage daemon LTO-2-0 at localhost:9103 ... 3306 Issuing autochanger "slots" command. Device "LTO-2-0" has 24 slots. Connecting to Storage daemon LTO-2-0 at localhost:9103 ... 3306 Issuing autochanger "list" command. The following Volumes will be labeled: Slot Volume ============== 2 000213 6 000160 7 000231 8 000161 9 000153 11 000155 13 000137 14 000156 15 000157 16 000168 17 000162 18 000159 19 000018 20 000129 21 000095 22 000158 23 000115 24 000154 Do you want to label these Volumes? (yes|no): yes Defined Pools: 1: Default 2: File 3: Scratch Select the Pool (1-3): 3 Connecting to Storage daemon LTO-2-0 at localhost:9103 ... Sending label command for Volume "000213" Slot 2 ... 3307 Issuing autochanger "unload slot 1, drive 0" command. # Note: There was an error with the tape in this slot

3995 Bad autochanger "unload slot 1, drive 0": ERR=Child exited with code 1 Results=Storage Element 1 is Already Full Label command failed for Volume 000213. # Could not enter label the tape for some reason Media record for Slot 6 Volume "000160" already exists. Sending label command for Volume "000231" Slot 7 ... 3301 Issuing autochanger "loaded? drive 0" command. 3302 Autochanger "loaded? drive 0", result is Slot 3. 3307 Issuing autochanger "unload slot 3, drive 0" command. 3304 Issuing autochanger "load slot 7, drive 0" command. 3305 Autochanger "load slot 7, drive 0", status is OK. block.c:1001 Read error on fd=4 at file:blk 0:0 on device "LTO-2-0" (/dev/nst0). ERR=Input/output error. # This is typical if this is a new tape. 3000 OK label. VolBytes=64512 DVD=0 Volume="000231" Device="LTO-2-0" (/dev/nst0) # Label created on the tape successfully Catalog record for Volume "000231", Slot 7 successfully created. Media record for Slot 8 Volume "000161" already exists. Media record for Slot 9 Volume "000153" already exists. Media record for Slot 11 Volume "000155" already exists. Media record for Slot 13 Volume "000137" already exists. Media record for Slot 14 Volume "000156" already exists. Media record for Slot 15 Volume "000157" already exists. # All of these are already in the system Media record for Slot 16 Volume "000168" already exists. Media record for Slot 17 Volume "000162" already exists. Media record for Slot 18 Volume "000159" already exists. Media record for Slot 19 Volume "000018" already exists. Media record for Slot 20 Volume "000129" already exists. Media record for Slot 21 Volume "000095" already exists. Media record for Slot 22 Volume "000158" already exists. Media record for Slot 23 Volume "000115" already exists. Media record for Slot 24 Volume "000154" already exists.

You will notice there was an error with the tape in slot 1. Well the changer automatically moved it to slot 2 during the process. I reran the Label command and it was successful:

Connecting to Storage daemon LTO-2-0 at localhost:9103 ... Sending label command for Volume "000213" Slot 2 ... 3307 Issuing autochanger "unload slot 7, drive 0" command. 3304 Issuing autochanger "load slot 2, drive 0" command. 3305 Autochanger "load slot 2, drive 0", status is OK. # Last time it said it was bad... block.c:1001 Read error on fd=5 at file:blk 0:0 on device "LTO-2-0" (/dev/nst0). ERR=Input/output error. # Expected, because the tape is new 3000 OK label. VolBytes=64512 DVD=0 Volume="000213" Device="LTO-2-0" (/dev/nst0) Catalog record for Volume "000213", Slot 2 successfully created. # Label created! Media record for Slot 3 Volume "000017" already exists. Media record for Slot 6 Volume "000160" already exists. Media record for Slot 7 Volume "000231" already exists. Media record for Slot 8 Volume "000161" already exists.

The /etc/bacula/scripts/bconsolescriptbarcodelabel.sh script used here is very simple as well:

#Copyright disclaimer:
#       Copyright (C) 2015,  ITHierarchy Inc (www.ithierarchy.com). ALl rights reserverd.
#       This program is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program.  If not, see <http://www.gnu.org/licenses/>.

#!  /bin/bash
bconsole -c  /etc/bacula/bconsole.conf <<END_OF_DATA
@output /dev/null
messages
@output

label barcodes
2
yes
3

Move Media slot to slot Custom Command:

This is the most complex of the custom commands. this one uses parameters that are menu boxes and get there values from another script. This script move tapes from one slot to an empty slot. that you choose.

  1. create a custom command as explained in "Creating Custom Commands"
    1. give it the Description "Move Media slot to slot"
    2. use the command: bash /etc/bacula/scripts/bconsoletestscriptMove.sh -s $ssource -d $ddestination
    3. We are going to have to create 2 parameters.
      1. The first parameter needs the following values:
        1. Parameter Name: ssource
        2. Description: Occupied Slot
        3. Type: Menu..
        4. in the textbox next to Type (note the "|" at the end of the line, This is required as it tell the box to use the output of the script): bash /etc/bacula/scripts/bconsolscriptusedslotsoutput.sh| 
        5. Quoted?: No
        6. Required?: Yes
      2. Click ​​Save (or Create)

         
      3. Now we need to edit the Move Media slot to slot custom command and add the second parameter, so from the Custom Commands screen, select  "Edit command." under "Move Media slot to slot".

         

      4. Now we need to create a second parameter for ddestination with  the following values:
        1. Parameter Name: ddestination
        2. Description: Empty Slots
        3. Type: Menu..
        4. in the textbox next to Type (note the "|" at the end of the line, This is required as it tell the box to use the output of the script): bash /etc/bacula/scripts/bconsolescriptemptyslotsoutput.sh|​ 
        5. Quoted?: No
        6. Required?: Yes
    4. Click Save.

Back at the Custom Commands screen you now have 2 dropdown boxes under Move Media slot to slot, the Source and the destination. I have selected Tape 000231 in slot 7 to move to slot 10:

​Here is the output, you will see that it moved the tape and updated the slot number to 10:

Output from bash /etc/bacula/scripts/bconsoletestscriptMove.sh -s tape:000231=Slot:7 -d 10 ..

Source=Slot: 7 Destination=Slot: 10 Connecting to Director localhost:9101 1000 OK: saninator-dir Version: 5.2.6 (21 February 2012) Enter a period to cancel a command. update Automatically selected Catalog: MyCatalog Using Catalog "MyCatalog" Update choice: 1: Volume parameters 2: Pool from resource 3: Slots from autochanger 4: Long term statistics Choose catalog item to update (1-4): 3 The defined Storage resources are: 1: File 2: LTO-2-0 Select Storage resource (1-2): 2 Connecting to Storage daemon LTO-2-0 at localhost:9103 ... 3306 Issuing autochanger "slots" command. Device "LTO-2-0" has 24 slots. Connecting to Storage daemon LTO-2-0 at localhost:9103 ... 3306 Issuing autochanger "list" command. Catalog record for Volume "000213" updated to reference slot 2. Catalog record for Volume "000017" updated to reference slot 3. Catalog record for Volume "000160" updated to reference slot 6. Catalog record for Volume "000161" updated to reference slot 8. Catalog record for Volume "000153" updated to reference slot 9. Catalog record for Volume "000231" updated to reference slot 10. Catalog record for Volume "000155" updated to reference slot 11. Catalog record for Volume "000137" updated to reference slot 13. Catalog record for Volume "000156" updated to reference slot 14. Catalog record for Volume "000157" updated to reference slot 15. Catalog record for Volume "000168" updated to reference slot 16. Catalog record for Volume "000162" updated to reference slot 17. Catalog record for Volume "000159" updated to reference slot 18. Catalog record for Volume "000018" updated to reference slot 19. Catalog record for Volume "000129" updated to reference slot 20. Catalog record for Volume "000095" updated to reference slot 21. Catalog record for Volume "000158" updated to reference slot 22. Catalog record for Volume "000115" updated to reference slot 23. Catalog record for Volume "000154" updated to reference slot 24. list media Pool: Default +---------+------------+-----------+---------+-----------------+----------+--------------+---------+------+-----------+-----------+---------------------+ | MediaId | VolumeName | VolStatus | Enabled | VolBytes | VolFiles | VolRetention | Recycle | Slot | InChanger | MediaType | LastWritten | +---------+------------+-----------+---------+-----------------+----------+--------------+---------+------+-----------+-----------+---------------------+ | 1 | 000129 | Full | 1 | 302,105,502,720 | 305 | 2,592,000 | 1 | 20 | 1 | LTO-2 | 2015-02-14 23:47:24 | | 2 | 000017 | Append | 1 | 456,343,437,312 | 458 | 2,592,000 | 1 | 3 | 1 | LTO-2 | 2015-02-15 04:09:16 | +---------+------------+-----------+---------+-----------------+----------+--------------+---------+------+-----------+-----------+---------------------+ Pool: File No results to list. Pool: Scratch +---------+------------+-----------+---------+----------+----------+--------------+---------+------+-----------+-----------+---------------------+ | MediaId | VolumeName | VolStatus | Enabled | VolBytes | VolFiles | VolRetention | Recycle | Slot | InChanger | MediaType | LastWritten | +---------+------------+-----------+---------+----------+----------+--------------+---------+------+-----------+-----------+---------------------+ | 3 | 000137 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 13 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 4 | 000095 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 21 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 5 | 000115 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 23 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 6 | 000018 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 19 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 7 | 000159 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 18 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 8 | 000160 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 6 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 9 | 000161 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 8 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 10 | 000153 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 9 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 11 | 000154 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 24 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 12 | 000155 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 11 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 13 | 000156 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 14 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 14 | 000157 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 15 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 15 | 000128 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 0 | 0 | LTO-2 | 0000-00-00 00:00:00 | | 16 | 000162 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 17 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 17 | 000168 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 16 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 18 | 000158 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 22 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 19 | 000231 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 10 | 1 | LTO-2 | 0000-00-00 00:00:00 | | 20 | 000213 | Append | 1 | 64,512 | 0 | 31,536,000 | 1 | 2 | 1 | LTO-2 | 0000-00-00 00:00:00 | +---------+------------+-----------+---------+----------+----------+--------------+---------+------+-----------+-----------+---------------------+

The scripts that are used are:

  • /etc/bacula/scripts/bconsoletestscriptMove.sh  - Which initiates the move.

#Copyright disclaimer:
#       Copyright (C) 2015,  ITHierarchy Inc (www.ithierarchy.com). ALl rights reserverd.
#       This program is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program.  If not, see <http://www.gnu.org/licenses/>.

#!/bin/bash
interactive=
destination=
source=

while getopts s:d: opt

do
    
    case "$opt" in
        s)     source=$OPTARG
                                ;;
        d)     destination=$OPTARG;;
    esac
done

asource="${source#*:}"
ssource="${asource#*:}"

echo "Source=Slot: $ssource"
echo "Destination=Slot: $destination"

mtx -f /dev/changer transfer ${ssource} $destination
sh /etc/bacula/scripts/bconsolescriptList.sh 

  • /etc/bacula/scripts/bconsolescriptList.sh - Which updates the location of tapes in the changer:

#Copyright disclaimer:
#    Copyright (C) 2015,  ITHierarchy Inc (www.ithierarchy.com). ALl rights reserverd.
#    This program is free software: you can redistribute it and/or modify
#        it under the terms of the GNU General Public License as published by
#        the Free Software Foundation, either version 3 of the License, or
#        (at your option) any later version.
#
#        This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty of
#        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#        GNU General Public License for more details.
#
#        You should have received a copy of the GNU General Public License
#        along with this program.  If not, see <http://www.gnu.org/licenses/>.

#!  /bin/bash

bconsole -c  /etc/bacula/bconsole.conf <<END_OF_DATA
update
3
2
list media
END_OF_DATA

  • /etc/bacula/scripts/bconsolscriptusedslotsoutput.sh - this Formats the output of /etc/bacula/scripts/bconsolscriptusedslots.sh for the  Source Slot menu options

#Copyright disclaimer:
#       Copyright (C) 2015,  ITHierarchy Inc (www.ithierarchy.com). ALl rights reserverd.
#       This program is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program.  If not, see <http://www.gnu.org/licenses/>.

#!/bin/bash
IFS=$'\n'

cmdoutput=($(sh /etc/bacula/scripts/bconsolscriptusedslots.sh))
searchstring="Catalog record for Volume "
cleanstr=""
#echo "Output is"
for i in "${cmdoutput[@]}"
do
#   :
   if [ "$i" = "${i%$searchstring*}" ]; then
c=$i
else
f=${i#*slot}
b=${i%updated*}
a=${b/$searchstring/$cleanstr}
c=${a/\"/$cleanstr}
d=${c/\"/$cleanstr}
e=${d/\ /$cleanstr}
g=${f/\ /$cleanstr}

echo "tape:$e=Slot:${g//./}"
fi
#echo "$i"
done

  • /etc/bacula/scripts/bconsolscriptusedslots.sh - Which gets the information on the location of tapes in the system

#Copyright disclaimer:
#       Copyright (C) 2015,  ITHierarchy Inc (www.ithierarchy.com). ALl rights reserverd.
#       This program is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program.  If not, see <http://www.gnu.org/licenses/>.

#!  /bin/bash
bconsole -c  /etc/bacula/bconsole.conf <<END_OF_DATA
@output /dev/null
update
3
@output 
2
END_OF_DATA

  •  /etc/bacula/scripts/bconsolescriptemptyslotsoutput.sh - Findes the empty slots an populates the empty slots menu box. This one also calls the /etc/bacula/scripts/bconsolscriptusedslots.sh​ script.

#Copyright disclaimer:
#       Copyright (C) 2015,  ITHierarchy Inc (www.ithierarchy.com). ALl rights reserverd.
#       This program is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program.  If not, see <http://www.gnu.org/licenses/>.

#!/bin/bash
IFS=$'\n'

cmdoutput=($(sh /etc/bacula/scripts/bconsolscriptusedslots.sh))
searchstring="Catalog record for Volume "
cleanstr=""
#echo "Output is"
for j in {1..24}
do
    k=0
    for i in "${cmdoutput[@]}"
    do
#   :
           if [ "$i" = "${i%$searchstring*}" ]; then
            c=$i
        else
            f=${i#*slot}
            b=${i%updated*}
            a=${b/$searchstring/$cleanstr}
            c=${a/\"/$cleanstr}
            d=${c/\"/$cleanstr}
            e=${d/\ /$cleanstr}
            g=${f/\ /$cleanstr}
            h=${g/\./}

            if [ "$j" = "$h" ] ; then
                k=1
            fi
        fi
    done
    if [ "$k" = "0" ] ; then
        echo $j
    fi
#echo "$i"
done

slot information Custom Command: 

This command just returns simple what tape is in what slot:

  1. create a custom command as explained in "Creating Custom Commands"
    1. give it the Description "slot information"
    2. use the command: bash /etc/bacula/scripts/bconsolscriptusedslotsoutputForUser.sh
    3. Leave everything else at the defaults. you also do not need any parameters.
    4. Click Save (or Create).
  2. Now test it:
    1. Go back to the Custom Commands and click slot Information

Inventory Changer custom command:

This custom command will force a Inventory of the tapes in the library.

Warning!!!: this custom command will briefly stop the bacula-sd service so it can initiate the inventory. do not run this command during backups!

  1. create a custom command as explained in "Creating Custom Commands"
    1. give it the Description "Media Information"
    2. We are going to use an HTML description on this one to place the warning above in the command box:
      <span style="color:#FF0000"><strong><em><span style="background-color:#FFFF00">Warning!!!: this custom command will briefly stop the </span><span style="background-color:#FFFF00">bacula</span><span style="background-color:#FFFF00">-sd service so it can initiate the inventory. do not run this command during backups!</span></em></strong></span>
    3. use the command: service bacula-sd stop; mtx -f /dev/changer inventory; service bacula-sd start​
    4. Leave everything else at the defaults. you also do not need any parameters.
    5. Click Save (or Create).
  2. Now test it:
    1. Go back to the Custom Commands and click Inventory Changer

There is no special output or scripts on this one, but after a few moments, you will see your changer starts to go through the tapes.

Other Bacula Articles

 

This has made for a great series of articles! including:

Comments