Split OpenAFS volumes in version 1.4.x

I had to split the volumes on my server, in order to ease the management. In the OpenAFS 1.5.x branch, the volume server has a vos split command, which is not available for 1.4.x installations. Moving the dat arraound is not an option, since it does not preserves the ACL data. I came up with the following script:

It has certain drawbacks, like it’s not a move command but a copy, because it’s based in the AFS up command, so it requires you to have enough free space on the partition. It is also required to use the full path of the directory to split like /afs/cell/somefolder/dirtosplit. Besides that, it helped me to automate the splitting of several huge volumes.

You can check the help with the -h option, and you can test that all variables are properly set before executing using the -t option.

Enjoy!

#!/bin/bash

CELL=
NEWVOLNAME=
DESTDIR=
PARTITION=
RMFLAG=
SERVER=
LOCALAUTH=
MAXQUOTA=
TEST=

while getopts 'hrltc:n:d:p:m:s:' opt
do
	case $opt in
	c)	CELL=\"$OPTARG\"
		;;
	n)	NEWVOLNAME="$OPTARG"
		;;
	d)	DESTDIR="$OPTARG"
		;;
	l)	LOCALAUTH="-localauth"
		;;
	m)	MAXQUOTA="-maxquota $OPTARG"
		;;
	p)	PARTITION="$OPTARG"
		;;
	r)	RMFLAG=1
		;;
	s)	SERVER="$OPTARG"
		;;
	t)	TEST=1
		;;
	h)	printf "Usage:\n\t%s: [parameters] srcdir\n\n" $(basename $0)
		printf "Split an OpenAFS volume at directory srcdir\n"
		printf "\t-c cellname\n"
		printf "\t-n name\tnew volume name\n"
		printf "\t-p partition\tthe partition for the new volume\n"
		printf "\t-r \t\tremove the source directory after copy\n"
		printf "\t-s server\tAFS server for the volume\n"
		printf "\t-d destination\tdirectory if you want a different one\n"
		printf "\t-l \t\tuse local authentication for vos server\n"
		printf "\t-m value\tset maxquota for new volume\n"
		printf "\t-t \t\ttest, print variables and exit\n"
		exit 2
		;;
	esac
done
shift $(($OPTIND - 1))

SRCDIR=$1

if [ ! "$DESTDIR" ]
then
	DESTDIR="$SRCDIR"
fi

# Add suffix .tmp to the source dir
TMPDIR="${SRCDIR}.tmp"

# Use the destination directory to build the RWDESTPATH, replace cellname with the rw path
RWDESTPATH=`echo "$DESTDIR" | sed -e "s/$CELL/.$CELL/"`

if [ $TEST ]
then
	echo cell="$CELL"
	echo volname="$NEWVOLNAME"
	echo partition="$PARTITION"
	echo server="$SERVER"
	echo src="$SRCDIR"
	echo dest="$DESTDIR"
	echo tmpdir="$TMPDIR"
	echo rwdestpath="$RWDESTPATH"
	echo localauth="$LOCALAUTH"
	echo maxquota="$MAXQUOTA"
	echo rmflag="$RMFLAG"
	exit 2
fi

# Rename the source directory
mv "$SRCDIR" "$TMPDIR"

# Create the new volume and mount it in the new position
echo "Creating new Volume: $NEWVOLNAME"
vos create -server $SERVER -partition $PARTITION -name $NEWVOLNAME $MAXQUOTA -cell $CELL $LOCALAUTH

echo "Mount Volume"
fs mkm "$RWDESTPATH" $NEWVOLNAME -rw

# Copy the data to the new location
echo "Copy data to new location"
afs-up "$TMPDIR" "$DESTDIR"

# Remove srcdir if specified
if [ "$RMFLAG" ]
then
	echo "Removing temp directory"
	rm -rf "$TMPDIR"
fi

Leave a Reply

Your email address will not be published. Required fields are marked *