#!/bin/sh
case $0 in
/*)
SMBCLIENT="`dirname $0`/smbclient";;
*) SMBCLIENT="smbclient";;
esac
server=""
service="backup" password=""
username=$LOGNAME verbose="2>/dev/null" log="-d 2"
newer=""
newerarg=""
blocksize=""
blocksizearg=""
clientargs="-c 'tarmode full'"
tarcmd="c"
tarargs=""
cdcmd="\\"
tapefile=${TAPE-tar.out}
Usage(){
ex=$1
shift
echo >&2 "Usage: `basename $0` [<options>] [<include/exclude files>]
Function: backup/restore a Windows PC directories to a local tape file
Options: (Description) (Default)
-r Restore from tape file to PC Save from PC to tapefile
-i Incremental mode Full backup mode
-a Reset archive bit mode Don't reset archive bit
-v Verbose mode: echo command Don't echo anything
-s <server> Specify PC Server $server
-p <password> Specify PC Password $password
-x <share> Specify PC Share $service
-X Exclude mode Include
-N <newer> File for date comparison `set -- $newer; echo $2`
-b <blocksize> Specify tape's blocksize `set -- $blocksize; echo $2`
-d <dir> Specify a directory in share $cdcmd
-l <log> Specify a Samba Log Level `set -- $log; echo $2`
-u <user> Specify User Name $username
-t <tape> Specify Tape device $tapefile
"
echo >&2 "$@"
exit $ex
}
if [ $
Usage 2 "Please enter a command line parameter!"
fi
while getopts riavl:b:d:N:s:p:x:u:Xt: c; do
case $c in
r) tarcmd="x"
;;
i) tarargs=${tarargs}ga
clientargs="-c 'tarmode inc'"
;;
a) tarargs=${tarargs}a
;;
l) log="-d $OPTARG"
case "$OPTARG" in
[0-9]*) ;;
*) echo >&2 "$0: Error, log level not numeric: -l $OPTARG"
exit 1
esac
;;
d) cdcmd="$OPTARG"
;;
N) if [ -f $OPTARG ]; then
newer=$OPTARG
newerarg="N"
else
echo >&2 $0: Warning, $OPTARG not found
fi
;;
X) tarargs=${tarargs}X
;;
s) server="$OPTARG"
;;
b) blocksize="$OPTARG"
case "$OPTARG" in
[0-9]*) ;;
*) echo >&2 "$0: Error, block size not numeric: -b $OPTARG"
exit 1
esac
blocksizearg="b"
;;
p) password="$OPTARG"
;;
x) service="$OPTARG"
;;
t) tapefile="$OPTARG"
;;
u) username="$OPTARG"
;;
v) verbose=""
;;
'?') Usage 2 "Invalid switch specified - abort."
;;
esac
done
shift `expr $OPTIND - 1`
if [ "$server" = "" ] || [ "$service" = "" ]; then
Usage 1 "No server or no service specified - abort."
fi
if [ -z "$verbose" ]; then
echo "server is $server"
echo "share is $service\\$cdcmd"
echo "tar args is $tarargs"
echo "tape is $tapefile"
echo "blocksize is $blocksize"
fi
tarargs=${tarargs}${blocksizearg}${newerarg}
eval $SMBCLIENT "'\\\\$server\\$service'" "'$password'" -U "'$username'" \
-E $log -D "'$cdcmd'" ${clientargs} \
-T${tarcmd}${tarargs} $blocksize $newer $tapefile '${1+"$@"}' $verbose