Amanda-Users

ammkvtapes.sh

2005-11-15 14:59:52
Subject: ammkvtapes.sh
From: "Stefan G. Weichinger" <sgw AT amanda DOT org>
To: amanda-users <amanda-users AT amanda DOT org>
Date: Tue, 15 Nov 2005 20:44:51 +0100

As I mentioned in another thread some minutes ago, I have done some generalization-work on a script by Gene Heskett, which he sent to me back in 2004.

This script is intended to help generating the necessary structures for a vtape-setup, creating the various virtual tapes and slots etc.

I dug up my latest version and post it here without further testing, please only use it after you have read the code.

Create the config-dir for your new vtape-config and set the parameters in amanda.conf accordingly.
After that you run

ammkvtapes.sh <newconfig>

and the script should read the necessary parameters out of your amanda.conf.

As always, patches welcome.
Thanks again to Gene for the first script,

Stefan.

--------

#!/bin/sh

#************************************************************************
## ammkvtapes.sh
## tool which creates the necessary directory-structure for the usage
## of the chg-disk tapechanger with AMANDA
##
## ammkvtapes reads various parameters out of amanda.conf and uses them
## to create the correct number of vtapes in the given vtape_dir
##
## First version by Gene Heskett
## Generalization and further improvements by Stefan G. Weichinger
## 2004
#************************************************************************

# Check for parameter, echo Usage-text
if [ -z $1 ]
then
  echo "Usage: ammkvtapes.sh [-f] <conf>"
  exit
fi

# Check, if force-flag is set, set config-string accordingly
case $1 in
-f)
   FORCE_DEL=1
   CONFIG=$2
   ;;
*)
   FORCE_DEL=0
   CONFIG=$1
;;
esac

# get path to amgetconf
AMGETCONF=`which amgetconf`
# get path to amlabel
AMLABEL=`which amlabel`
# check if chg-disk is used in this config
TPCHANGER=$($AMGETCONF $CONFIG tpchanger)

echo "TPCHANGER : " $TPCHANGER

if [ $TPCHANGER ]; then
if [ $TPCHANGER = "chg-disk" ]; then
        echo "Configuration uses $TPCHANGER - OK"
        else
echo "Parameter tpchanger set to $TPCHANGER, has to be chg-disk - EXIT"
        exit
fi
else
echo "Parameter tpchanger not set for configuration $CONFIG - EXIT"
exit
fi

# get dir where configs are located
# e.g. /usr/local/etc/amanda
CONF_DIR=$($AMGETCONF $CONFIG build.config_dir)
# build dir-string for current config
# e.g. /usr/local/etc/amanda/daily
CUR_CONF_DIR="$CONF_DIR$CONFIG"
# get the path of the vtape-directory
# e.g. /amandatapes
VTAPE_DIR=$($AMGETCONF $CONFIG tapedev)
# strip away the file
VTAPE_DIR=${VTAPE_DIR#file\:}
# get number of tapes
NUM_TAPES=$($AMGETCONF $CONFIG tapecycle)
# get Label-string
LABEL_STR=$($AMGETCONF $CONFIG labelstr)
# get the dumpuser
DUMPUSER=$($AMGETCONF $CONFIG dumpuser)


## DEBUG-echos
echo "FORCE : " $FORCE_DEL
echo $AMGETCONF
echo "CONFIG : " $CONFIG
echo "CONF_DIR :  " $CONF_DIR
echo "CUR_CONF_DIR : " $CUR_CONF_DIR
echo "VTAPE-DIR : " $VTAPE_DIR
echo "NUM_TAPES : " $NUM_TAPES
echo "LABEL_STR : " $LABEL_STR


if [ -d $VTAPE_DIR ]; then
        echo "found existing tape-dir at " $VTAPE_DIR
        if [ $FORCE_DEL = "1" ]; then
                echo "ATTENTION - force-flag set !!!"
        #       rm -fR $VTAPE_DIR
        else
                echo "leaving stuff unchanged - no force-flag set"
        fi
fi


TAPELIST="$CUR_CONF_DIR/tapelist"

if [ -d $TAPELIST ]; then
        echo "found existing tapelist: " $TAPELIST
echo "Please remove this file manually if you are sure this is what you want."
        exit
fi

touch $TAPELIST

for n in 1 to $NUM_TAPES
do
         mkdir -p $VTAPE_DIR/slot${n}
         chmod -v 750 $VTAPE_DIR/slot${n}
         rm -f $VTAPE_DIR/data
         ln -s $VTAPE_DIR/slot${n} $VTAPE_DIR/data
         $AMLABEL $CONF daily${n} slot ${n}
done


## Give the Vtapes to the dumpuser
chown -R $DUMPUSER $VTAPE_DIR

## rm the link amlabel leaves
rm $VTAPE_DIR/data
## reset it for slot 1
amtape $CONFIG slot 1

echo
echo "created $NUM_TAPES slot-dirs successfully."
echo
## show it to the user (me)
ls -l $VTAPE_DIR

## show all the vtapes by using amtape

amtape $CONFIG show

echo "OK"

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



<Prev in Thread] Current Thread [Next in Thread>