1996-05-04 11:50:46 +04:00
#!/bin/sh
#
# smbtar script - front end to smbclient
#
# Authors: Martin.Kraemer <Martin.Kraemer@mch.sni.de>
# and Ricky Poulten (ricky@logcam.co.uk)
#
# (May need to change shell to ksh for HPUX or OSF for better getopts)
1998-08-21 13:01:30 +04:00
#
1998-11-21 12:29:35 +03:00
# sandy nov 3 '98 added -a flag
#
1998-08-21 13:01:30 +04:00
# Richard Sharpe, added -c 'tarmode full' so that we back up all files to
# fix a bug in clitar when a patch was added to stop system and hidden files
# being backed up.
1996-05-04 11:50:46 +04:00
case $0 in
2022-02-21 16:11:19 +03:00
# when called by absolute path, assume smbclient is in the same directory
/*)
SMBCLIENT="$(dirname $0)/smbclient"
;;
*) # you may need to edit this to show where your smbclient is
SMBCLIENT="smbclient" ;;
1996-05-04 11:50:46 +04:00
esac
# These are the default values. You could fill them in if you know what
# you're doing, but beware: better not store a plain text password!
server=""
2022-02-21 16:11:19 +03:00
service="backup" # Default: a service called "backup"
1996-05-04 11:50:46 +04:00
password=""
2022-02-21 16:11:19 +03:00
username=$LOGNAME # Default: same user name as in *nix
verbose="2>/dev/null" # Default: no echo to stdout
1996-05-04 11:50:46 +04:00
log="-d 2"
newer=""
1999-12-13 16:27:58 +03:00
newerarg=""
1996-05-04 11:50:46 +04:00
blocksize=""
1999-12-13 16:27:58 +03:00
blocksizearg=""
1998-08-21 13:01:30 +04:00
clientargs="-c 'tarmode full'"
1996-05-04 11:50:46 +04:00
tarcmd="c"
tarargs=""
cdcmd="\\"
tapefile=${TAPE-tar.out}
2022-02-21 16:11:19 +03:00
Usage()
{
ex=$1
shift
echo >&2 "Usage: $(basename $0) [<options>] [<include/exclude files>]
1996-05-04 11:50:46 +04:00
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
1998-11-21 12:29:35 +03:00
-a Reset archive bit mode Don't reset archive bit
1996-05-04 11:50:46 +04:00
-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
2022-02-21 16:11:19 +03:00
-N <newer> File for date comparison $(
set -- $newer
echo $2
)
-b <blocksize> Specify tape's blocksize $(
set -- $blocksize
echo $2
)
1996-05-04 11:50:46 +04:00
-d <dir> Specify a directory in share $cdcmd
2022-02-21 16:11:19 +03:00
-l <log> Specify a Samba Log Level $(
set -- $log
echo $2
)
1996-05-04 11:50:46 +04:00
-u <user> Specify User Name $username
-t <tape> Specify Tape device $tapefile
"
2022-02-21 16:11:19 +03:00
echo >&2 "$@"
exit $ex
1996-05-04 11:50:46 +04:00
}
1999-12-13 16:27:58 +03:00
# echo Params count: $#
1998-07-07 02:25:56 +04:00
2022-02-21 16:11:19 +03:00
# DEC OSF AKA Digital UNIX does not seem to return a value in OPTIND if
1998-07-07 02:25:56 +04:00
# there are no command line params, so protect us against that ...
if [ $# = 0 ]; then
2022-02-21 16:11:19 +03:00
Usage 2 "Please enter a command line parameter!"
1998-07-07 02:25:56 +04:00
fi
1998-11-21 12:29:35 +03:00
while getopts riavl:b:d:N:s:p:x:u:Xt: c; do
2022-02-21 16:11:19 +03:00
case $c in
r) # [r]estore to Windows (instead of the default "Save from Windows")
tarcmd="x"
;;
i) # [i]ncremental
tarargs=${tarargs}ga
clientargs="-c 'tarmode inc'"
;;
a) # [a]rchive
tarargs=${tarargs}a
;;
l) # specify [l]og file
log="-d $OPTARG"
case "$OPTARG" in
[0-9]*) ;;
*)
echo >&2 "$0: Error, log level not numeric: -l $OPTARG"
exit 1
;;
esac
;;
d) # specify [d]irectory to change to in server's share
cdcmd="$OPTARG"
;;
N) # compare with a file, test if [n]ewer
if [ -f $OPTARG ]; then
newer=$OPTARG
newerarg="N"
else
echo >&2 $0: Warning, $OPTARG not found
fi
;;
X) # Add exclude flag
tarargs=${tarargs}X
;;
s) # specify [s]erver's share to connect to - this MUST be given.
server="$OPTARG"
;;
b) # specify [b]locksize
blocksize="$OPTARG"
case "$OPTARG" in
[0-9]*) ;;
*)
echo >&2 "$0: Error, block size not numeric: -b $OPTARG"
exit 1
;;
esac
blocksizearg="b"
;;
p) # specify [p]assword to use
password="$OPTARG"
;;
x) # specify windows [s]hare to use
service="$OPTARG"
;;
t) # specify [t]apefile on local host
tapefile="$OPTARG"
;;
u) # specify [u]sername for connection
username="$OPTARG"
;;
v) # be [v]erbose and display what's going on
verbose=""
tarargs=${tarargs}v
;;
'?') # any other switch
Usage 2 "Invalid switch specified - abort."
;;
esac
1996-05-04 11:50:46 +04:00
done
2022-02-21 16:11:19 +03:00
shift $(expr $OPTIND - 1)
1996-05-04 11:50:46 +04:00
if [ "$server" = "" ] || [ "$service" = "" ]; then
2022-02-21 16:11:19 +03:00
Usage 1 "No server or no service specified - abort."
1996-05-04 11:50:46 +04:00
fi
# if the -v switch is set, the echo the current parameters
if [ -z "$verbose" ]; then
2022-02-21 16:11:19 +03:00
echo "server is $server"
# echo "share is $service"
echo "share is $service\\$cdcmd"
echo "tar args is $tarargs"
# echo "password is $password" # passwords should never be sent to screen
echo "tape is $tapefile"
echo "blocksize is $blocksize"
1996-05-04 11:50:46 +04:00
fi
1999-12-13 16:27:58 +03:00
tarargs=${tarargs}${blocksizearg}${newerarg}
1996-05-04 11:50:46 +04:00
eval $SMBCLIENT "'\\\\$server\\$service'" "'$password'" -U "'$username'" \
2022-02-21 16:11:19 +03:00
-E $log -D "'$cdcmd'" ${clientargs} \
-T${tarcmd}${tarargs} $blocksize $newer $tapefile '${1+"$@"}' $verbose