add --list
[hombase.git] / other-sh / rsync-all.sh
blob496707383ff07fd2e076861f50812c63342aaf0f
1 #!/bin/sh
3 #rsync-all.sh-- _describe_
4 #@Author: LiFan
5 #@Created: 2011-04-02-11:49
7 PATH=/usr/local/bin:/bin:/usr/bin
9 error()
11 echo "$@" 1>&2
12 usage_and_exit 1
15 usage()
17 echo "Usage: $PROGRAM [--all] [--list] [--athome|-m] [--mode|-o <put|get|put-update|get-update>] [--dry|-n] <--tohost|-t> [--help] [--version] [the component...]"
18 echo "rsync to ip98:"
19 echo -e "\trsync-all.sh -a -t ip98:"
20 echo -e "\trsync-all.sh -t ip98: update"
21 echo -e "\trsync-all.sh -t ip98: fox"
22 echo "rsync to 1T:"
23 echo -e "\trsync-all.sh -t ip98:/cygdrive/h/li\@58 update"
24 echo -e "\trsync-all.sh -t ip98:/cygdrive/h/li\@58 local-backup"
25 #echo "rsync to 67.195 at localhost: by port 32195"
26 #echo -e "\trsync-all.sh localhost: qa 32195"
27 echo "rsync to ip 108"
28 echo -e "\trsync-all.sh -t 192.168.1.108: update"
29 echo "rsync to local path /cygdrive/h"
30 echo -e "\trsync-all.sh -t /cygdrive/h update"
31 echo "rsync to tu58 for get update and just test"
32 echo -e "\trsync-all.sh -o get -n -t tu58: update"
35 usage_and_exit()
37 usage
38 exit $1
41 version()
43 echo "$PROGRAM version $VERSION"
46 warning()
48 echo "$@" 1>&2
49 EXITCODE=$((EXITCODE + 1))
50 #EXITCODE=`expr $EXITCODE + 1`
54 EXITCODE=0
55 PROGRAM=`basename $0`
56 VERSION=1.0
57 all=no
58 mode=put
59 dry=false
60 user=lifan
61 port=22
62 #components=
63 hosts=
65 hostname=`hostname`
66 if [ $hostname = "football12" ]
67 then
68 athome=yes
69 else
70 athome=no
74 while test $# -gt 0
76 case $1 in
77 --all | -a)
78 all=yes
80 --help | -h)
81 usage_and_exit 0
83 --version | -v)
84 version
85 exit 0
87 --list | -l)
88 all=list
90 --athome| -m)
91 athome=yes
93 --mode| -o)
94 shift
95 mode=$1
97 --dry-run| -n)
98 dry=true
100 --tohost| -t)
101 shift
102 hosts="$hosts $1"
105 error "Unrecognized option: $1"
108 break
110 esac
111 shift
112 done
114 #----------- end of phrase argument ---------------#
116 rsync1()
118 echo "in rsync1"
119 host1=$1
120 shift
121 host2=$1
122 shift
123 echo rsync $* $host1 $host2
124 rsync $* $host1 $host2
127 rsync2()
129 echo "in rsync2"
130 host1=$1
131 shift
132 host2=$1
133 shift
134 echo rsync $* $host2 $host1
135 rsync $* $host2 $host1
138 if [ "$all" = "list" ]
139 then
140 echo -e "componets:\n\tupdate: /e/update /e/ori\n\tfox: /l/scrapbook/\n\tmiranda\n\tlb: /l/local-backup/\n\t"
141 exit 0
145 if [ -z "$hosts" ]
146 then
147 error "tohost must set!!!"
151 if [ $all == "yes" ]
152 then
153 echo "use all setting, means sync update and fox"
154 componets="update fox"
155 else
156 if [ $# -eq 0 ]
157 then
158 error "component or -a must set!!!"
159 else
160 echo $*
161 components=$*
165 # -a: archive mode, equivalent to -rlptgoD
166 # -v: increase verbosity
167 # -z: compress file data
168 # --delete: This tells rsync to delete any files on the receiving side that aren't on the send-ing side
169 case $mode in
170 put)
171 echo "use mode put and delete"
172 ARGU="-avz --delete"
173 rsync_func=rsync1
175 get)
176 echo "use mode get and delete"
177 ARGU="-avz --delete"
178 rsync_func=rsync2
180 put-update)
181 echo "use mode put and update and not delete"
182 ARGU="-avzub"
183 rsync_func=rsync1
185 get-update)
186 echo "use mode get and update and not delete"
187 ARGU="-avzub"
188 rsync_func=rsync2
191 error "mode error"
192 exit 1
194 esac
196 if [ $dry == "true" ]
197 then
198 ARGU="$ARGU --dry-run"
201 echo $components
202 for i in $components
204 case $i in
205 update)
206 echo "in update component..."
207 # can use i again at here ???
208 for j in $hosts
210 echo rsync to $j...
211 $rsync_func /e/ori/ $j/e/ori/ $ARGU
212 $rsync_func /e/update/ $j/e/update/ $ARGU
213 done
215 fox)
216 echo "in fox component ..."
217 for j in $hosts
219 echo rsync to $j...
220 $rsync_func /l/scrapbook/ $j/l_disk/scrapbook/ $ARGU
221 $rsync_func $HOME/syncplaces.json $j/e/home/$user/syncplaces.json $ARGU
222 $rsync_func $HOME/syncplaces.json.sha1 $j/e/home/$user/syncplaces.json.sha1 $ARGU
223 $rsync_func /d/temp.txt $j/d/temp.txt $ARGU
224 done
226 miranda)
227 echo "in miranda componet ..."
228 for j in $hosts
230 echo rsync to $j...
231 $rsync_func /d/prog/miranda-ing/ $j/d/prog/miranda-ing/ $ARGU
232 done
235 echo "in local-backup componet ..."
236 for j in $hosts
238 echo rsync to $j...
239 $rsync_func /l/local-backup/ $j/e/l_disk/local-backup/ $ARGU
240 done
243 echo "in $i component ..."
244 for j in $hosts
246 echo rsync to $j...
247 $rsync_func $i/ $j$i/ $ARGU
248 done
250 esac
251 done