If you don't know that amanda is a portable Unix backup and restore facility, you probably aren't interested in this article.
Amanda can use virtual tapes, vtapes for short. With disk space as cheap and reliable as it is, I've been using vtapes for years now. Every once in a while, I need to create more "tapes". This script helps me do that.
# Make slots as specified on the command line.
# syntax: makeslots <config> start stop
# Where start and stop are the slot numbers to create. They should
# continue from the last that already exists. Gaps do you no good.
config=$1
if [ "$config" = "-h" ] || [ "$config" = "--help" ] \
|| [ $# != 3 ] ; then
echo makeslots: config start stop
exit
fi
path=$(gettapedev.pl ${config})
if [ $? != '0' ] ; then
echo Path ${path} is invalid!
exit
fi
cd ${path}
if [ $? != '0' ] ; then
echo Path ${path} is invalid!
exit
fi
for i in $(seq $2 $3 ) ; do
echo $i ;
if [ -e slot$i ] ; then
echo "slot$i exists. Not making it."
else
mkdir -p slot$i
chmod 0700 slot$i # privacy & security.
amlabel ${config} ${config}_$( printf %02d $i) slot $i
fi
done
You may want to customize the label parameter to amlabel to suit your labelstr (as defined in the appropriate amanda.conf
).
You could hard code the path. But that gets problematic if you have multiple amanda configurations and multiple sets of vtapes, or if you move your vtapes around. So a short perl program gets the vtape path from the relevant configuration, gettapedev.pl
.
I wrote this function in Perl because I am lazy. The Amanda Perl modules have a tool for parsing an Amanda configuration file. I just use that to pull the tape device out of the configuration file. That is the directory in which Amanda stores its virtual tapes. As luck would have it, one of the examples in the POD was almost exactly what I needed.
The code depends on knowing where the Amanda Perl libraries are. Adjust the use lib
line for your installation and you should be set. Note that we strip out the "file:" protocol specification. If you feed these scripts the name of a configuration that uses physical tapes, the results are undefined and probably not what you want.
#! /usr/bin/perl -w
# Note, you may have to adjust this path:
# use lib "/usr/lib/amanda/perl"; # 1:3.3.6-4 & earlier (??)
use lib "/usr/lib/x86_64-linux-gnu/amanda/perl/"; # 1:3.4.3-1
use strict;
use Amanda::Config qw( :init :getconf );
my $config_name = shift @ARGV;
config_init($CONFIG_INIT_EXPLICIT_NAME, $config_name);
# apply_config_overrides($config_overrides);
my ($cfgerr_level, @cfgerr_errors) = config_errors();
if ($cfgerr_level >= $CFGERR_WARNINGS) {
config_print_errors();
if ($cfgerr_level >= $CFGERR_ERRORS) {
die("errors processing config file");
}
}
# tapedev and chg-disk seem to be the preferred variables for 3.4.3.
my $tapeDev = getconf($CNF_TAPEDEV);
if (length ($tapeDev) == 0) {
$tapeDev = getconf($CNF_TPCHANGER);
}
$tapeDev =~ s/^chg-disk://g;
$tapeDev =~ s/^file://g;
print $tapeDev;
Enjoy!