#!/bin/sh
#ifdef IDENT
#ident "@(#)sapclone.sh 1.1 97/02/10 Copyright (c) 1996, Legato Systems, Inc."
#endif
#
# (C) Copyright 1996, Legato Systems, Inc.
# All rights reserved.
#
# Clone SAP Module savesets
#

usage="Usage: $1 [ -a ] [ -b pool ] [ -n ] [ -s server ] -u user"

set -- `getopt ab:ns:u: $*`
if [ $? != 0 ]
then
	echo $USAGE
	exit 2
fi

cutoff="-t yesterday"
pool=""
server=""

for i in $*
do
	case $i in
	-a)	cutoff="-a";	 shift;;		# Actually, mminfo -N implies this
	-b)	pool="-b $2";	 shift 2;;
	-n)	trial_run=1;	 shift;;
	-s)	server="-s $2";	 shift 2;;
	-u)	user="$2";	 shift 2;;
	esac
done

if [ -z "$user" ]
then
	echo -u user missing
	echo $usage
	exit 2
fi

savesets=`mminfo $cutoff -N backint:$user -r ssid`

if [ -n "$trial_run" ]
then
	echo The following saveset ids would have been cloned:
	echo $savesets | fmt
	exit 0
fi

echo Initiating cloning of following saveset ids:
echo $savesets | fmt
echo

nsrclone -v $pool $server -S $savesets
