made "hide files" and "veto files" into per-service parameter sections,
[Samba.git] / source / script / smbtar
bloba947476dc6ba7629351a2eb083ca18313cda815c
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 case $0 in
11 # when called by absolute path, assume smbclient is in the same directory
12 /*)
13 SMBCLIENT="`dirname $0`/smbclient";;
14 *) # you may need to edit this to show where your smbclient is
15 SMBCLIENT="smbclient";;
16 esac
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!
20 server=""
21 service="backup" # Default: a service called "backup"
22 password=""
23 username=$LOGNAME # Default: same user name as in *nix
24 verbose="2>/dev/null" # Default: no echo to stdout
25 log="-d 2"
26 newer=""
27 blocksize=""
28 tarcmd="c"
29 tarargs=""
30 cdcmd="\\"
31 tapefile=${TAPE-tar.out}
33 Usage(){
34 ex=$1
35 shift
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
53 echo >&2 "$@"
54 exit $ex
57 while getopts rivl:b:d:N:s:p:x:u:Xt: c; do
58 case $c in
59 r) # [r]estore to Windows (instead of the default "Save from Windows")
60 tarcmd="x"
62 i) # [i]ncremental
63 tarargs=${tarargs}g
65 l) # specify [l]og file
66 log="-d $OPTARG"
67 case "$OPTARG" in
68 [0-9]*) ;;
69 *) echo >&2 "$0: Error, log level not numeric: -l $OPTARG"
70 exit 1
71 esac
73 d) # specify [d]irectory to change to in server's share
74 cdcmd="$OPTARG"
76 N) # compare with a file, test if [n]ewer
77 if [ -f $OPTARG ]; then
78 newer=$OPTARG
79 tarargs=${tarargs}N
80 else
81 echo >&2 $0: Warning, $OPTARG not found
84 X) # Add exclude flag
85 tarargs=${tarargs}X
87 s) # specify [s]erver's share to connect to - this MUST be given.
88 server="$OPTARG"
90 b) # specify [b]locksize
91 blocksize="blocksize $OPTARG"
92 case "$OPTARG" in
93 [0-9]*) ;;
94 *) echo >&2 "$0: Error, block size not numeric: -b $OPTARG"
95 exit 1
96 esac
97 tarargs=${tarargs}b
99 p) # specify [p]assword to use
100 password="$OPTARG"
102 x) # specify windows [s]hare to use
103 service="$OPTARG"
105 t) # specify [t]apefile on local host
106 tapefile="$OPTARG"
108 u) # specify [u]sername for connection
109 username="$OPTARG"
111 v) # be [v]erbose and display what's going on
112 verbose=""
114 '?') # any other switch
115 Usage 2 "Invalid switch specified - abort."
117 esac
118 done
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