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)
11 # when called by absolute path, assume smbclient is in the same directory
13 SMBCLIENT
="`dirname $0`/smbclient";;
14 *) # you may need to edit this to show where your smbclient is
15 SMBCLIENT
="smbclient";;
18 # These are the default values. You could fill them in if you know what
19 # you're doing, but beware: better not store a plain text password!
21 service
="backup" # Default: a service called "backup"
23 username
=$LOGNAME # Default: same user name as in *nix
24 verbose
="2>/dev/null" # Default: no echo to stdout
31 tapefile
=${TAPE-tar.out}
36 echo >&2 "Usage: `basename $0` [<options>] [<include/exclude files>]
37 Function: backup/restore a Windows PC directories to a local tape file
38 Options: (Description) (Default)
39 -r Restore from tape file to PC Save from PC to tapefile
40 -i Incremental mode Full backup mode
41 -v Verbose mode: echo command Don't echo anything
42 -s <server> Specify PC Server $server
43 -p <password> Specify PC Password $password
44 -x <share> Specify PC Share $service
45 -X Exclude mode Include
46 -N <newer> File for date comparison `set -- $newer; echo $2`
47 -b <blocksize> Specify tape's blocksize `set -- $blocksize; echo $2`
48 -d <dir> Specify a directory in share $cdcmd
49 -l <log> Specify a Samba Log Level `set -- $log; echo $2`
50 -u <user> Specify User Name $username
51 -t <tape> Specify Tape device $tapefile
57 while getopts rivl
:b
:d
:N
:s
:p
:x
:u
:Xt
: c
; do
59 r
) # [r]estore to Windows (instead of the default "Save from Windows")
65 l
) # specify [l]og file
69 *) echo >&2 "$0: Error, log level not numeric: -l $OPTARG"
73 d
) # specify [d]irectory to change to in server's share
76 N
) # compare with a file, test if [n]ewer
77 if [ -f $OPTARG ]; then
81 echo >&2 $0: Warning
, $OPTARG not found
87 s
) # specify [s]erver's share to connect to - this MUST be given.
90 b
) # specify [b]locksize
91 blocksize
="blocksize $OPTARG"
94 *) echo >&2 "$0: Error, block size not numeric: -b $OPTARG"
99 p
) # specify [p]assword to use
102 x
) # specify windows [s]hare to use
105 t
) # specify [t]apefile on local host
108 u
) # specify [u]sername for connection
111 v
) # be [v]erbose and display what's going on
114 '?') # any other switch
115 Usage
2 "Invalid switch specified - abort."
120 shift `expr $OPTIND - 1`
122 if [ "$server" = "" ] ||
[ "$service" = "" ]; then
123 Usage
1 "No server or no service specified - abort."
126 # if the -v switch is set, the echo the current parameters
127 if [ -z "$verbose" ]; then
128 echo "server is $server"
129 # echo "share is $service"
130 echo "share is $service\\$cdcmd"
131 echo "tar args is $tarargs"
132 # echo "password is $password" # passwords should never be sent to screen
133 echo "tape is $tapefile"
134 echo "blocksize is $blocksize"
137 eval $SMBCLIENT "'\\\\$server\\$service'" "'$password'" -U "'$username'" \
138 -E -N $log -D "'$cdcmd'" \
139 -T${tarcmd}${tarargs} $blocksize $newer $tapefile $
* $verbose