Bacula-users

[Bacula-users] please test autoimporttscript with a charger

2010-03-21 16:52:09
Subject: [Bacula-users] please test autoimporttscript with a charger
From: Mario Hosse <mario.hosse AT bode-wipper DOT de>
To: bacula-users AT lists.sourceforge DOT net
Date: Sun, 21 Mar 2010 21:31:45 +0100 (CET)
Hi all,

I 've written an autoimportscript for charger that search the last full
mailslot, last empty slot and transfer a tape from mailslot in the last
empty slot. Please help me to make my script a little bit better. I can
only test the script with charger with one mailslot. If you have a
charger with more mailslots, please test my script! I need the script to
import for weekly tapes from a safe.


requirements:
-charger with one or more mailsslots # test ibm ts3100 with bacula 3.0.2
under sles 11
-labeled tapes

here the script:

---------------------------------------------------------------------------------------
#!/bin/bash

#these script is for a automatic import from mailslots in freeslots of
charger as runbeforejob.sh in bacula type admin
#the function searches the last freeslot, the last full mailsslot, bring
tape in the freeslot and to start over to no freeslot or full mailslot
available!

#You have to setup it! Look under bacula-sd.conf item "Autochanger"
subitem "Changer Device = XXXXX"
CHANGERDEVICE=/dev/sg1

#You have to setup it! Look under bacula-dir.conf item "Storage" subitem
"Name = XXXXX"
STORAGE=Tape-Storage


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


##########################################################################################
#description search last free slot in CHANGERDEVICE
#sed 1: search in mtx status out where rows string that have "Storage
Element to Empty"
#sed 1: Suche in der Ausgabe von mtx alle Zeilen die "Storage Element
bis Empty" beinhalten
#sed 2: search rows with string "Import/Export-Slots" and delete them
#sed 2: Suche Import/Export-Slots und entferne diese Zeilen
#sed 3: get the last row
#sed 3: nimmt nur die letzte Zeile
#sed 4: replace the section "Storage Element " with nothing
#sed 4: ersetze den Abschnitt "Storage Element " mit nichts
#sed 5: replace the section ":Empty" with nothing
#sed 5: ersetze :Empty mit nichts
#output is the last free slotnumber from changerdevice
#Ergebnis ist eine freie Slotnummer

###########################################################################################
FREESLOT=`mtx -f $CHANGERDEVICE status | sed -n -e '/^.*Storage
Element.*Empty/p' | sed -e '/^.*Storage Element.*IMPORT\/EXPORT/d' |
sed  -e '$!d' | sed -e 's/^.*Storage Element //g' | sed -e
's/:Empty//g'`

if [ -z $FREESLOT ]; then
           
            FREESLOT=0
    else
            FREESLOT=$FREESLOT
fi

#echo FREESLOT=$FREESLOT


##########################################################################################
#description count "full" mailslots
#sed 1: search in output from mtx all rows they have string "Storage
Element xx Import/Export:Full"
#sed 1: Suche in der Ausgabe von mtx alle Zeilen die "Storage Element xx
Import/Export:Full" beinhalten
#sed 2: count the rows
#sed 2: Zähle die Anzahl dieser Zeilen

###########################################################################################

COUNTMAILSLOTS=`mtx -f $CHANGERDEVICE status | sed -n -e '/^.*Storage
Element.*IMPORT\/EXPORT:Full/p' | sed $= -n`

if [ -z $COUNTMAILSLOTS ]; then
           
            COUNTMAILSLOTS=0
    else
            COUNTMAILSLOTS=$COUNTMAILSLOTS
fi

#echo COUNTMAILSLOTS=$COUNTMAILSLOTS


###########################################################################################
#description search "full" Mailslots
# sed 1: search in output from mtx all rows they have string "Storage
Element xx Import/Export:Full"
#sed 1: Suche in der Ausgabe von mtx alle Zeilen die Storage Element bis
"IMPORT/EXPORT:Full" beinhalten
#sed 2: get only the last row
#sed 2: nimmt nur die letzte Zeile
#sed 3: replace the section "Storage Element " with nothing
#sed 3: ersetze den Abschnitt Storage Element mit nichts
#sed 4: replace the section " IMPORT/EXPORT:.*" with nothing
#sed 4: ersetze " IMPORT/EXPORT:.*" mit nichts
#return a full Mailslot
#Ergebnis ist ein voller MAILSLOT

###########################################################################################

MAILSLOTNUMBER=`mtx -f $CHANGERDEVICE status | sed -n -e '/^.*Storage
Element.*IMPORT\/EXPORT:Full/p' | sed  -e '$!d' | sed -e 's/^.*Storage
Element //g' | sed -e 's@ IMPORT/EXPORT:.*@@g'`

if [ -z $MAILSLOTNUMBER ]; then
           
            MAILSLOTNUMBER=0
    else
            MAILSLOTNUMBER=$MAILSLOTNUMBER
fi

#echo MAILSLOTNUMBER=$MAILSLOTNUMBER


###########################################################################################
#description Mailslot Status
# sed 1: search in output from mtx all rows they have string "Storage
Element xx IMPORT/EXPORT"
#sed 1: Suche in der Ausgabe von mtx alle Zeilen die "Storage Element xx
IMPORT/EXPORT" beinhalten
#sed 2: replace the section "Storage Element xx IMPORT/EXPORT:" with
nothing
#sed 2: ersetze den Abschnitt "Storage Element xx IMPORT/EXPORT:" mit
nichts
#sed 3: replace the section ":VolumeTag=to the end" with nothing
#sed 3: ersetze ":VolumeTag=bis zum Ende" mit nichts

###########################################################################################

#MAILSLOTSTATUS=`mtx -f $CHANGERDEVICE status | sed -n -e '/^.*Storage
Element.*IMPORT\/EXPORT/p' | sed -e 's@Storage
Element.*IMPORT/EXPORT:@@g' | sed -e 's@:VolumeTag=.*@@g'`
#echo MAILSLOTSTATUS=$MAILSLOTSTATUS


#check 3x Variable >0
if [ $COUNTMAILSLOTS -gt 0 ] && [ $MAILSLOTNUMBER -gt 0 ] && [ $FREESLOT
-gt 0 ]; then

        #loop count  full Mailslots and bring in freeslots
        for (( ATTEMPT = 1 ; $ATTEMPT <= $COUNTMAILSLOTS ; ATTEMPT++ ))
; do
           
                    echo "Mailslot $MAILSLOTNUMBER is full!"
                    mtx -f $CHANGERDEVICE transfer $MAILSLOTNUMBER
$FREESLOT
                    echo "Move Tape from Mailslot $MAILSLOTNUMBER in
Slot $FREESLOT perfekt!"

                   
##############################################################
                    ## 1. Ensure the DB is up to date                  
                                     ##
                    ## 1. update bacule db-Slots                        
                                      ##
                   
##############################################################
                    echo "update slots
Storage=$STORAGE"|/usr/sbin/bconsole > /dev/null
                    echo "update slots Storage=$STORAGE"


                    FREESLOT=`mtx -f $CHANGERDEVICE status | sed -n -e
'/^.*Storage Element.*Empty/p' | sed -e '/^.*Storage
Element.*IMPORT\/EXPORT/d' | sed  -e '$!d' | sed -e 's/^.*Storage
Element //g' | sed -e 's/:Empty//g'`

                    if [ -z $FREESLOT ]; then
                            FREESLOT=0
                    else
                            FREESLOT=$FREESLOT
                    fi
                   
                        if [ $FREESLOT -eq 0 ]; then
                                echo "No Freeslot available!"
                        else
                                echo FREESLOT=$FREESLOT
                        fi

                    MAILSLOTNUMBER=`mtx -f $CHANGERDEVICE status | sed
-n -e '/^.*Storage Element.*IMPORT\/EXPORT:Full/p' | sed  -e '$!d' | sed
-e 's/^.*Storage Element //g' | sed -e 's@ IMPORT/EXPORT:.*@@g'`

                    if [ -z $MAILSLOTNUMBER ]; then
                            MAILSLOTNUMBER=0
                    else
                            MAILSLOTNUMBER=$MAILSLOTNUMBER
                    fi
                   
                        if [ $MAILSLOTNUMBER -eq 0 ]; then
                                echo "No Mailsot available!"
                        else
                                echo MAILSLOTNUMBER=$MAILSLOTNUMBER
                        fi


                    if [ $CODE -ne 0 ]; then
                        exit $CODE
                    fi
                        echo "That is it!"
                        exit 0
   
        done
                exit 0

    else
                    #check what is the Problem and get out per echo
                    if [ $FREESLOT -gt 0 ] && [ $MAILSLOTNUMBER -eq 0 ];
then

                        echo "Freeslot=$FREESLOT"
                        echo "Mailslot is blank!"
                        exit 0

                    elif [ $FREESLOT -eq 0 ] && [ $MAILSLOTNUMBER -eq 0
]; then
                   
                        echo "No free Slot and no full Mailslot
available!"
                        exit 0
                       
                    else
                   
                        echo "No Freeslot available!"
                        echo "Mailslot is $MAILSLOTNUMBER!"
                        exit 0

                    fi
   
    fi
        exit 0


---------------------------------------------------------------------------------------

greetings

Mario Hosse

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users
<Prev in Thread] Current Thread [Next in Thread>