Debian Codegraph @

source3/script/smbtar

raw symbols SCIP
1 #!/bin/sh
2 #
3 # smbtar script - front end to smbclient
4 #
5 # Authors: Martin.Kraemer <[email protected]>
6 # and Ricky Poulten ([email protected])
7 #
8 # (May need to change shell to ksh for HPUX or OSF for better getopts)
9 #
10 # sandy nov 3 '98 added -a flag
11 #
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
14 # being backed up.
15
16 case $0 in
17 # when called by absolute path, assume smbclient is in the same directory
18 /*)
19 SMBCLIENT="$(dirname $0)/smbclient"
20 ;;
21 *) # you may need to edit this to show where your smbclient is
22 SMBCLIENT="smbclient" ;;
23 esac
24
25 # These are the default values. You could fill them in if you know what
26 # you're doing, but beware: better not store a plain text password!
27 server=""
28 service="backup" # Default: a service called "backup"
29 password=""
30 username=$LOGNAME # Default: same user name as in *nix
31 verbose="2>/dev/null" # Default: no echo to stdout
32 log="-d 2"
33 newer=""
34 newerarg=""
35 blocksize=""
36 blocksizearg=""
37 clientargs="-c 'tarmode full'"
38 tarcmd="c"
39 tarargs=""
40 cdcmd="\\"
41 tapefile=${TAPE-tar.out}
42
43 Usage()
44 {
45 ex=$1
46 shift
47 echo >&2 "Usage: $(basename $0) [<options>] [<include/exclude files>]
48 Function: backup/restore a Windows PC directories to a local tape file
49 Options: (Description) (Default)
50 -r Restore from tape file to PC Save from PC to tapefile
51 -i Incremental mode Full backup mode
52 -a Reset archive bit mode Don't reset archive bit
53 -v Verbose mode: echo command Don't echo anything
54 -s <server> Specify PC Server $server
55 -p <password> Specify PC Password $password
56 -x <share> Specify PC Share $service
57 -X Exclude mode Include
58 -N <newer> File for date comparison $(
59 set -- $newer
60 echo $2
61 )
62 -b <blocksize> Specify tape's blocksize $(
63 set -- $blocksize
64 echo $2
65 )
66 -d <dir> Specify a directory in share $cdcmd
67 -l <log> Specify a Samba Log Level $(
68 set -- $log
69 echo $2
70 )
71 -u <user> Specify User Name $username
72 -t <tape> Specify Tape device $tapefile
73 "
74 echo >&2 "$@"
75 exit $ex
76 }
77
78 # echo Params count: $#
79
80 # DEC OSF AKA Digital UNIX does not seem to return a value in OPTIND if
81 # there are no command line params, so protect us against that ...
82 if [ $# = 0 ]; then
83
84 Usage 2 "Please enter a command line parameter!"
85
86 fi
87
88 while getopts riavl:b:d:N:s:p:x:u:Xt: c; do
89 case $c in
90 r) # [r]estore to Windows (instead of the default "Save from Windows")
91 tarcmd="x"
92 ;;
93 i) # [i]ncremental
94 tarargs=${tarargs}ga
95 clientargs="-c 'tarmode inc'"
96 ;;
97 a) # [a]rchive
98 tarargs=${tarargs}a
99 ;;
100 l) # specify [l]og file
101 log="-d $OPTARG"
102 case "$OPTARG" in
103 [0-9]*) ;;
104 *)
105 echo >&2 "$0: Error, log level not numeric: -l $OPTARG"
106 exit 1
107 ;;
108 esac
109 ;;
110 d) # specify [d]irectory to change to in server's share
111 cdcmd="$OPTARG"
112 ;;
113 N) # compare with a file, test if [n]ewer
114 if [ -f $OPTARG ]; then
115 newer=$OPTARG
116 newerarg="N"
117 else
118 echo >&2 $0: Warning, $OPTARG not found
119 fi
120 ;;
121 X) # Add exclude flag
122 tarargs=${tarargs}X
123 ;;
124 s) # specify [s]erver's share to connect to - this MUST be given.
125 server="$OPTARG"
126 ;;
127 b) # specify [b]locksize
128 blocksize="$OPTARG"
129 case "$OPTARG" in
130 [0-9]*) ;;
131 *)
132 echo >&2 "$0: Error, block size not numeric: -b $OPTARG"
133 exit 1
134 ;;
135 esac
136 blocksizearg="b"
137 ;;
138 p) # specify [p]assword to use
139 password="$OPTARG"
140 ;;
141 x) # specify windows [s]hare to use
142 service="$OPTARG"
143 ;;
144 t) # specify [t]apefile on local host
145 tapefile="$OPTARG"
146 ;;
147 u) # specify [u]sername for connection
148 username="$OPTARG"
149 ;;
150 v) # be [v]erbose and display what's going on
151 verbose=""
152 tarargs=${tarargs}v
153 ;;
154 '?') # any other switch
155 Usage 2 "Invalid switch specified - abort."
156 ;;
157 esac
158 done
159
160 shift $(expr $OPTIND - 1)
161
162 if [ "$server" = "" ] || [ "$service" = "" ]; then
163 Usage 1 "No server or no service specified - abort."
164 fi
165
166 # if the -v switch is set, the echo the current parameters
167 if [ -z "$verbose" ]; then
168 echo "server is $server"
169 # echo "share is $service"
170 echo "share is $service\\$cdcmd"
171 echo "tar args is $tarargs"
172 # echo "password is $password" # passwords should never be sent to screen
173 echo "tape is $tapefile"
174 echo "blocksize is $blocksize"
175 fi
176
177 tarargs=${tarargs}${blocksizearg}${newerarg}
178
179 eval $SMBCLIENT "'\\\\$server\\$service'" "'$password'" -U "'$username'" \
180 -E $log -D "'$cdcmd'" ${clientargs} \
181 -T${tarcmd}${tarargs} $blocksize $newer $tapefile '${1+"$@"}' $verbose