Bacula Erasing Tapes And Automatic Labeling Script
I have been using Bacula since 2005.
About a year ago, I obtained about 200 HP Lto4 tapes from i dismantled It project. They were no longer used at work until now.
In order for me to use them again, I needed to erase the tapes without disabling the bacula storage daemon and needed to add i new label to them.
Based upon an existing script on the internet “https://dan.langille.org/2011/05/27/bacula-removing-labels-then-labeling-tapes/”, I wrote this script.
With this, I can insert new tapes, add an external barcode label, put the mazagine in the tape library, and in 30 minutes, have new volumes.
#!/bin/sh
#
# Copyright 2014-2014 Pedro Oliveira
#
# This script should be read in conjunction with
# http://www.freebsddiary.org/tape-testing.php
#
# Nice Bacula Gui - Use Reportula
# http://www.reportula.org
#
# Change this to the location of your script
#
MTX="/etc/bacula/mtx-changer"
CHANGER="/dev/${1}"
DRIVE="/dev/${2}"
BEGINSLOT="/dev/${3}"
ENDSLOT="/dev/${4}"
POOL="${5}"
STORAGE="${6}"
LOGGER=/usr/bin/logger
ECHO=/bin/echo
for slot in {$BEGINSLOT..$ENDSLOT}
do
${ECHO} loading $slot
${MTX} ${CHANGER} load $slot ${DRIVE} 0
mt -f ${DRIVE} rewind
mt -f ${DRIVE} weof
mt -f ${DRIVE} rewind
# now label that slot
bconsole END_OF_DATA
label barcodes pool=$POOL storage=$STORAGE slot=${slot}
1
yes
umount storage=$STORAGE
quit
END_OF_DATA
done
To run this script, I issue this command:
time sudo sh ~/bin/EraseTapeLabels pass11 sa0 1 200 poolname storagename
where
time – tells me how long the rest of the command takes
sudo – I am running this as non-root; sudo makes me root
pass11 – my tape changer
sa0 – the tape drive
1 – Initial Slot
200 – Slot End
Poolname – Name of the pool to insert the new Volumes
Storagename – Name of the Storage to label the new Volumes
Best Regards use freely