3 # smbtar script - front end to smbclient
5 # Authors: Martin.Kraemer <Martin.Kraemer@mch.sni.de>
6 # and Ricky Poulten (ricky@logcam.co.uk)
8 # (May need to change shell to ksh for HPUX or OSF for better getopts)
10 # sandy nov 3 '98 added -a flag
12 # Richard Sharpe, added -c 'tarmode full' so that we back up all files to
13 # fix a bug in clitar when a patch was added to stop system and hidden files
17 # when called by absolute path, assume smbclient is in the same directory
19 SMBCLIENT
="`dirname $0`/smbclient";;
20 *) # you may need to edit this to show where your smbclient is
21 SMBCLIENT
="smbclient";;
24 # These are the default values. You could fill them in if you know what
25 # you're doing, but beware: better not store a plain text password!
27 service
="backup" # Default: a service called "backup"
29 username
=$LOGNAME # Default: same user name as in *nix
30 verbose
="2>/dev/null" # Default: no echo to stdout
36 clientargs
="-c 'tarmode full'"
40 tapefile
=${TAPE-tar.out}
45 echo >&2 "Usage: `basename $0` [<options>] [<include/exclude files>]
46 Function: backup/restore a Windows PC directories to a local tape file
47 Options: (Description) (Default)
48 -r Restore from tape file to PC Save from PC to tapefile
49 -i Incremental mode Full backup mode
50 -a Reset archive bit mode Don't reset archive bit
51 -v Verbose mode: echo command Don't echo anything
52 -s <server> Specify PC Server $server
53 -p <password> Specify PC Password $password
54 -x <share> Specify PC Share $service
55 -X Exclude mode Include
56 -N <newer> File for date comparison `set -- $newer; echo $2`
57 -b <blocksize> Specify tape's blocksize `set -- $blocksize; echo $2`
58 -d <dir> Specify a directory in share $cdcmd
59 -l <log> Specify a Samba Log Level `set -- $log; echo $2`
60 -u <user> Specify User Name $username
61 -t <tape> Specify Tape device $tapefile
67 # echo Params count: $#
69 # DEC OSF AKA Digital UNIX does not seem to return a value in OPTIND if
70 # there are no command line params, so protect us against that ...
73 Usage
2 "Please enter a command line parameter!"
77 while getopts riavl
:b
:d
:N
:s
:p
:x
:u
:Xt
: c
; do
79 r
) # [r]estore to Windows (instead of the default "Save from Windows")
84 clientargs
="-c 'tarmode inc'"
89 l
) # specify [l]og file
93 *) echo >&2 "$0: Error, log level not numeric: -l $OPTARG"
97 d
) # specify [d]irectory to change to in server's share
100 N
) # compare with a file, test if [n]ewer
101 if [ -f $OPTARG ]; then
105 echo >&2 $0: Warning
, $OPTARG not found
108 X
) # Add exclude flag
111 s
) # specify [s]erver's share to connect to - this MUST be given.
114 b
) # specify [b]locksize
118 *) echo >&2 "$0: Error, block size not numeric: -b $OPTARG"
123 p
) # specify [p]assword to use
126 x
) # specify windows [s]hare to use
129 t
) # specify [t]apefile on local host
132 u
) # specify [u]sername for connection
135 v
) # be [v]erbose and display what's going on
138 '?') # any other switch
139 Usage
2 "Invalid switch specified - abort."
144 shift `expr $OPTIND - 1`
146 if [ "$server" = "" ] ||
[ "$service" = "" ]; then
147 Usage
1 "No server or no service specified - abort."
150 # if the -v switch is set, the echo the current parameters
151 if [ -z "$verbose" ]; then
152 echo "server is $server"
153 # echo "share is $service"
154 echo "share is $service\\$cdcmd"
155 echo "tar args is $tarargs"
156 # echo "password is $password" # passwords should never be sent to screen
157 echo "tape is $tapefile"
158 echo "blocksize is $blocksize"
161 tarargs
=${tarargs}${blocksizearg}${newerarg}
163 eval $SMBCLIENT "'\\\\$server\\$service'" "'$password'" -U "'$username'" \
164 -E $log -D "'$cdcmd'" ${clientargs} \
165 -T${tarcmd}${tarargs} $blocksize $newer $tapefile '${1+"$@"}' $verbose