Revision 62

bin/zfs-replica (revision 62)
10 10
getConfigSnapshotTool="/sbin/get-conf-snapshot"
11 11
zfsSnapshot="/sbin/zfs-snapshot"
12 12
FILE_NAME=$1
13
TEMP_FILE_NAME="$1-tmp"
14
>$TEMP_FILE_NAME
13 15
BINZFS="/sbin/zfs"
14 16
BINZPOOL="/sbin/zpool"
15 17

  
......
160 162
    $BINZFS send $snapshot2replicate | $BINZFS recv $namereplica
161 163
    if [[ "$?" == "0" ]]
162 164
    then
163
       cpt=0
164 165
       while read line
165 166
       do 
166
         if [ $cpt -eq 0 ]
167
         then
168
            echo $line
169
            $(echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >$FILE_NAME)
170
            cpt=1
171
         else
172
            $(echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >>$FILE_NAME)
173
         fi 
167
            $(echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >>$TEMP_FILE_NAME)
174 168
       done <<< "$(cat $FILE_NAME)"
169
       /bin/rm $FILE_NAME
170
       /bin/mv $TEMP_FILE_NAME $FILE_NAME
175 171
       del_old_snapshot
172
       exit 0
176 173
    fi 
177 174
   
178 175
else
......
188 185
    $BINZFS send $snapshot2replicate |ssh -o BatchMode=yes root@$server $BINZFS recv $namereplica
189 186
    if [[ "$?" == "0" ]]
190 187
    then
191
       cpt=0
192 188
       while read line
193 189
       do 
194
         if [ $cpt -eq 0 ]
195
         then
196
            echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >$FILE_NAME
197
            cpt=1
198
         else
199
            echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >>$FILE_NAME
200
         fi
190
            $(echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >>$TEMP_FILE_NAME)
201 191
       done <<< "$(cat $FILE_NAME)"
192
       /bin/rm $FILE_NAME
193
       /bin/mv $TEMP_FILE_NAME $FILE_NAME
202 194
       del_old_snapshot
195
       exit 0
203 196
    fi 
204 197
  fi
205
exit 0
206 198
fi
207 199

  
208 200
}
......
211 203

  
212 204
function incremental_replication {
213 205

  
214
echo "Start incremental replication"
206
echo "Start incremental replication for : $snasphot2replicate"
215 207
if [[ "$server" == "" ]]
216 208
then
217
    $BINZFS send -i $lastsnapshotReplicated $namevolfs@$snaphot2replicate | $BINZFS recv $namereplica
209
    $BINZFS send -i $lastsnapshotReplicated $namevolfs@$snasphot2replicate | $BINZFS recv $namereplica
210
    snapshot2replicate="$namevolfs@$snasphot2replicate"
218 211
    if [[ "$?" == "0" ]]
219 212
    then
220
       cpt=0
221 213
       while read line
222
       do 
223
         echo $line
224
         if [ $cpt -eq 0 ]
225
         then
226
            echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >$FILE_NAME
227
            cpt=1
228
         else
229
            echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >$FILE_NAME
230
         fi
214
       do
215
            echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g"
231 216
       done <<< "$(cat $FILE_NAME)"
217
       /bin/rm $FILE_NAME
218
       /bin/mv $TEMP_FILE_NAME $FILE_NAME
232 219
       del_old_snapshot
220
       exit 0
233 221
    fi 
234
   
235 222
else
236 223
  checkServerConnection
237
if [ "$snaphot2replicate" == "" ]
224
if [ "$snasphot2replicate" == "" ]
238 225
then
239 226
   exit 1
240 227
else
241
    $BINZFS send -i $lastsnapshotReplicated $namevolfs@$snaphot2replicate | ssh -o BatchMode=yes root@$server $BINZFS recv $namereplica
228
    $BINZFS send -i $lastsnapshotReplicated $namevolfs@$snasphot2replicate | ssh -o BatchMode=yes root@$server $BINZFS recv $namereplica
229
    snapshot2replicate="$namevolfs@$snasphot2replicate"
242 230
    if [[ "$?" == "0" ]]
243 231
    then
244
       cpt=0
245 232
       while read line
246 233
       do 
247
         echo $line
248
         if [ $cpt -eq 0 ]
249
         then
250
            echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$namevolfs@$snaphot2replicate:g" >$FILE_NAME
251
            cpt=1
252
         else
253
            echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$namevolfs@$snaphot2replicate:g" >>$FILE_NAME
254
         fi
234
            $(echo $line|sed -e "s:lastsnapshotreplicated=.*$:lastsnapshotreplicated=$snapshot2replicate:g" >>$TEMP_FILE_NAME)
255 235
       done <<< "$(cat $FILE_NAME)"
236
       /bin/rm $FILE_NAME
237
       /bin/mv $TEMP_FILE_NAME $FILE_NAME
256 238
       del_old_snapshot
239
       exit 0
257 240
    fi 
258 241
  fi
259 242
fi
......
292 275

  
293 276

  
294 277
#--- FULL REPLICATION ---#
295
if [[ $NBsnaphot -eq 1 ]] || [[ "$lastsnapshotReplicated" == "" ]]
278
if [[ $NBsnasphot -eq 1 ]] || [[ "$lastsnapshotReplicated" == "" ]]
296 279
then
297 280
   echo "Replication by incremental snapshot is not possible"
298 281
   echo "Start FULL Replication ..."
......
312 295

  
313 296
    if [[ $cpt -eq 1 ]]
314 297
    then
315
       snaphot2replicate=$(echo $line |sed -e "s/ \+/ /g"|cut -d " " -f1|cut -d "@" -f2)
316
       echo $lastsnaphot
317
       echo $snaphot2replicate
298
       snasphot2replicate=$(echo $line |sed -e "s/ \+/ /g"|cut -d " " -f1|cut -d "@" -f2)
299
       echo $lastsnasphot
300
       echo $snasphot2replicate
318 301
       break
319 302
    fi
320 303
    cpt=$cpt+1
321 304
  done <<< "$($BINZFS list -H -r -t snapshot $namevolfs|tac)"
322 305
  lastsnapshot=$(echo $lastsnapshotReplicated |sed -e "s/ \+/ /g"|cut -d " " -f1|cut -d "@" -f2) 
323 306
 
324
  if [ "$snaphot2replicate" == "$lastsnapshot" ]
307
  if [ "$snasphot2replicate" == "$lastsnapshot" ]
325 308
  then
326 309
     echo "Nothing to replicate" 1>&2
327 310
     exit 1
......
330 313
  if [ "$server" == "" ]
331 314
  then
332 315
     check_lastsnapshotReplica=$($BINZFS list -H -r -t snapshot $namereplica |grep $lastsnapshot|wc -l)
333
     check_currentsnapshotReplica=$($BINZFS list -H -r -t snapshot $namereplica |grep $snaphot2replicate=|wc -l)
316
     check_currentsnapshotReplica=$($BINZFS list -H -r -t snapshot $namereplica |grep $snasphot2replicate=|wc -l)
334 317
  else
335 318
     check_lastsnapshotReplica=$(ssh -o BatchMode=yes root@$server $BINZFS list -H -r -t snapshot $namereplica |grep $lastsnapshot|wc -l)
336
     check_currentsnapshotReplica=$(ssh -o BatchMode=yes root@$server $BINZFS list -H -r -t snapshot $namereplica |grep $snaphot2replicate=|wc -l)
319
     check_currentsnapshotReplica=$(ssh -o BatchMode=yes root@$server $BINZFS list -H -r -t snapshot $namereplica |grep $snasphot2replicate=|wc -l)
337 320
  fi
338 321
  if [[ $check_lastsnapshotReplica -eq 0 ]]
339 322
  then
......
347 330
    exit 1
348 331
  fi  
349 332
fi
350
 echo $snaphot2replicate
333
 echo $snasphot2replicate
351 334
incremental_replication
352 335
}
353 336

  

Also available in: Unified diff