Submitting the smbtar changes to the main branch as well.
[Samba/gbeck.git] / source3 / script / smbtar
blob25c36b2a8f7959ef11ccd74753218188f92ce04a
1 #!/bin/sh
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 # Richard Sharpe, added -c 'tarmode full' so that we back up all files to
11 # fix a bug in clitar when a patch was added to stop system and hidden files
12 # being backed up.
14 case $0 in
15 # when called by absolute path, assume smbclient is in the same directory
16 /*)
17 SMBCLIENT="`dirname $0`/smbclient";;
18 *) # you may need to edit this to show where your smbclient is
19 SMBCLIENT="smbclient";;
20 esac
22 # These are the default values. You could fill them in if you know what
23 # you're doing, but beware: better not store a plain text password!
24 server=""
25 service="backup" # Default: a service called "backup"
26 password=""
27 username=$LOGNAME # Default: same user name as in *nix
28 verbose="2>/dev/null" # Default: no echo to stdout
29 log="-d 2"
30 newer=""
31 blocksize=""
32 clientargs="-c 'tarmode full'"
33 tarcmd="c"
34 tarargs=""
35 cdcmd="\\"
36 tapefile=${TAPE-tar.out}
38 Usage(){
39 ex=$1
40 shift
41 echo >&2 "Usage: `basename $0` [<options>] [<include/exclude files>]
42 Function: backup/restore a Windows PC directories to a local tape file
43 Options: (Description) (Default)
44 -r Restore from tape file to PC Save from PC to tapefile
45 -i Incremental mode Full backup mode
46 -v Verbose mode: echo command Don't echo anything
47 -s <server> Specify PC Server $server
48 -p <password> Specify PC Password $password
49 -x <share> Specify PC Share $service
50 -X Exclude mode Include
51 -N <newer> File for date comparison `set -- $newer; echo $2`
52 -b <blocksize> Specify tape's blocksize `set -- $blocksize; echo $2`
53 -d <dir> Specify a directory in share $cdcmd
54 -l <log> Specify a Samba Log Level `set -- $log; echo $2`
55 -u <user> Specify User Name $username
56 -t <tape> Specify Tape device $tapefile
58 echo >&2 "$@"
59 exit $ex
62 echo Params count: $#
64 # DEC OSF AKA Digital UNIX does not seem to return a value in OPTIND if
65 # there are no command line params, so protect us against that ...
66 if [ $# = 0 ]; then
68 Usage 2 "Please enter a command line parameter!"
72 while getopts rivl:b:d:N:s:p:x:u:Xt: c; do
73 case $c in
74 r) # [r]estore to Windows (instead of the default "Save from Windows")
75 tarcmd="x"
77 i) # [i]ncremental
78 tarargs=${tarargs}g
80 l) # specify [l]og file
81 log="-d $OPTARG"
82 case "$OPTARG" in
83 [0-9]*) ;;
84 *) echo >&2 "$0: Error, log level not numeric: -l $OPTARG"
85 exit 1
86 esac
88 d) # specify [d]irectory to change to in server's share
89 cdcmd="$OPTARG"
91 N) # compare with a file, test if [n]ewer
92 if [ -f $OPTARG ]; then
93 newer=$OPTARG
94 tarargs=${tarargs}N
95 else
96 echo >&2 $0: Warning, $OPTARG not found
99 X) # Add exclude flag
100 tarargs=${tarargs}X
102 s) # specify [s]erver's share to connect to - this MUST be given.
103 server="$OPTARG"
105 b) # specify [b]locksize
106 blocksize="$OPTARG"
107 case "$OPTARG" in
108 [0-9]*) ;;
109 *) echo >&2 "$0: Error, block size not numeric: -b $OPTARG"
110 exit 1
111 esac
112 tarargs=${tarargs}b
114 p) # specify [p]assword to use
115 password="$OPTARG"
117 x) # specify windows [s]hare to use
118 service="$OPTARG"
120 t) # specify [t]apefile on local host
121 tapefile="$OPTARG"
123 u) # specify [u]sername for connection
124 username="$OPTARG"
126 v) # be [v]erbose and display what's going on
127 verbose=""
129 '?') # any other switch
130 Usage 2 "Invalid switch specified - abort."
132 esac
133 done
135 shift `expr $OPTIND - 1`
137 if [ "$server" = "" ] || [ "$service" = "" ]; then
138 Usage 1 "No server or no service specified - abort."
141 # if the -v switch is set, the echo the current parameters
142 if [ -z "$verbose" ]; then
143 echo "server is $server"
144 # echo "share is $service"
145 echo "share is $service\\$cdcmd"
146 echo "tar args is $tarargs"
147 # echo "password is $password" # passwords should never be sent to screen
148 echo "tape is $tapefile"
149 echo "blocksize is $blocksize"
152 eval $SMBCLIENT "'\\\\$server\\$service'" "'$password'" -U "'$username'" \
153 -E -N $log -D "'$cdcmd'" ${clientargs} \
154 -T${tarcmd}${tarargs} $blocksize $newer $tapefile $* $verbose