Révision 49 bin/zfs-replica

zfs-replica (revision 49)
6 6
getConfigSnapshotTool="/sbin/get-conf-snapshot"
7 7
zfsSnapshot="/sbin/zfs-snapshot"
8 8
FILE_NAME=$1
9
BINZFS="/sbin/zfs"
10
BINZPOOL="/sbin/zpool"
9 11

  
10 12
#********************************
11 13
#* function initenv
......
66 68
}
67 69

  
68 70
function checkCoherence {
69
  ssh -o BatchMode=yes root@$server zfs list $namereplica
71
  ssh -o BatchMode=yes root@$server $BINZFS list $namereplica
70 72
  if [ "$?" != "0" ]
71 73
  then
72 74
     return false
......
79 81
if [[ "$server" == "" ]]
80 82
then
81 83
  echo ""
82
  CPT_SNAP=$(/sbin/zfs list -t snapshot -r $namereplica |cut -d" " -f1 |grep -i $namereplica\@ |wc -l)
84
  CPT_SNAP=$($BINZFS list -t snapshot -r $namereplica |cut -d" " -f1 |grep -i $namereplica\@ |wc -l)
83 85
  echo "*** Number of snapshots for $namereplica is : $CPT_SNAP"
84
  /sbin/zfs list -t snapshot -r $namereplica
86
  $BINZFS list -t snapshot -r $namereplica
85 87

  
86 88
  if [ $CPT_SNAP -gt $nbreplica ]
87 89
  then
88 90
    echo "*** Detection of the oldest snapshot"
89
    for ID_SNAP_OLDER in $(/sbin/zfs list -t snapshot -r $namereplica |cut -d" " -f1 |grep -i $namereplica\@)
91
    for ID_SNAP_OLDER in $($BINZFS list -t snapshot -r $namereplica |cut -d" " -f1 |grep -i $namereplica\@)
90 92
    do
91 93
      echo "*** The oldest snapshot is : $ID_SNAP_OLDER"
92 94
      break
93 95
    done
94
    /sbin/zfs destroy $ID_SNAP_OLDER
96
    $BINZFS destroy $ID_SNAP_OLDER
95 97
    if [ $? -eq 0 ]
96 98
    then
97 99
       echo "*** Remove the snapshot $ID_SNAP_OLDER [OK]"
......
102 104

  
103 105
else
104 106
  echo ""
105
  CPT_SNAP=$(ssh -o BatchMode=yes root@$server /sbin/zfs list -t snapshot -r $namereplica |cut -d" " -f1 |grep -i $namereplica\@ |wc -l)
107
  CPT_SNAP=$(ssh -o BatchMode=yes root@$server $BINZFS list -t snapshot -r $namereplica |cut -d" " -f1 |grep -i $namereplica\@ |wc -l)
106 108
  echo "*** Number of snapshots for $namereplica is : $CPT_SNAP"
107
  ssh -o BatchMode=yes root@$server /sbin/zfs list -t snapshot -r $namereplica
109
  ssh -o BatchMode=yes root@$server $BINZFS list -t snapshot -r $namereplica
108 110

  
109 111
  if [ $CPT_SNAP -gt $nbreplica ]
110 112
  then
111 113
    echo "*** Detection of the oldest snapshot"
112
    for ID_SNAP_OLDER in $(ssh -o BatchMode=yes root@$server /sbin/zfs list -t snapshot -r $namereplica |cut -d" " -f1 |grep -i $namereplica\@)
114
    for ID_SNAP_OLDER in $(ssh -o BatchMode=yes root@$server $BINZFS list -t snapshot -r $namereplica |cut -d" " -f1 |grep -i $namereplica\@)
113 115
    do
114 116
      echo "*** The oldest snapshot is : $ID_SNAP_OLDER"
115 117
      break
116 118
    done
117
    ssh -o BatchMode=yes root@$server /sbin/zfs destroy $ID_SNAP_OLDER
119
    ssh -o BatchMode=yes root@$server $BINZFS destroy $ID_SNAP_OLDER
118 120
    if [ $? -eq 0 ]
119 121
    then
120 122
       echo "*** Remove the snapshot $ID_SNAP_OLDER [OK]"
......
145 147
if [[ "$server" == "" ]]
146 148
then
147 149

  
148
    /sbin/zfs list $parentdataset
150
    $BINZFS list $parentdataset
149 151
    if [[ "?" != "0" ]]
150 152
    then
151
      /sbin/zfs create -p $parentdataset
153
      $BINZFS create -p $parentdataset
152 154
    fi
153 155

  
154
    /sbin/zfs send $snapshot2replicate | /sbin/zfs recv $namereplica
156
    $BINZFS send $snapshot2replicate | $BINZFS recv $namereplica
155 157
    if [[ "$?" == "0" ]]
156 158
    then
157 159
       cpt=0
......
173 175
  checkServerConnection
174 176
  if [[ "$snapshot2replicate" != "" ]]
175 177
  then
176
    ssh -o BatchMode=yes root@$server /sbin/zfs list $parentdataset
178
    ssh -o BatchMode=yes root@$server $BINZFS list $parentdataset
177 179
    if [[ "?" != "0" ]]
178 180
    then
179
      ssh -o BatchMode=yes root@$server /sbin/zfs create -p $parentdataset
181
      ssh -o BatchMode=yes root@$server $BINZFS create -p $parentdataset
180 182
    fi
181 183

  
182
    /sbin/zfs send $snapshot2replicate |ssh -o BatchMode=yes root@$server /sbin/zfs recv $namereplica
184
    $BINZFS send $snapshot2replicate |ssh -o BatchMode=yes root@$server $BINZFS recv $namereplica
183 185
    if [[ "$?" == "0" ]]
184 186
    then
185 187
       cpt=0
......
208 210
echo "Start incremental replication"
209 211
if [[ "$server" == "" ]]
210 212
then
211
    cmd="zfs send -i $lastsnapshotReplicated $namevolfs@$lastsnaphot | ssh -o BatchMode=yes root@$server zfs recv $namereplica"
213
    cmd="$BINZFS send -i $lastsnapshotReplicated $namevolfs@$lastsnaphot | ssh -o BatchMode=yes root@$server $BINZFS recv $namereplica"
212 214
    echo $cmd
213 215
    if [[ "$?" == "0" ]]
214 216
    then
......
232 234
then
233 235
   exit 1
234 236
else
235
    /sbin/zfs send -i $lastsnapshotReplicated $namevolfs@$snaphot2replicate | ssh -o BatchMode=yes root@$server /sbin/zfs recv $namereplica
237
    $BINZFS send -i $lastsnapshotReplicated $namevolfs@$snaphot2replicate | ssh -o BatchMode=yes root@$server $BINZFS recv $namereplica
236 238
    if [[ "$?" == "0" ]]
237 239
    then
238 240
       cpt=0
......
264 266
initenv
265 267

  
266 268
fileconf=$($getConfigSnapshotTool $namevolfs|grep fileconf|cut -d "=" -f2)
267
NBsnapshot=$(/sbin/zfs list -H -r -t snapshot $namevolfs|wc -l)
269
NBsnapshot=$($BINZFS list -H -r -t snapshot $namevolfs|wc -l)
268 270

  
269 271
if [[ $NBsnapshot -eq 0 ]]
270 272
then
......
280 282
   while read line
281 283
   do
282 284
     snapshot2replicate=$(echo $line |echo $line |sed -e "s/ \+/ /g"|cut -d " " -f1)
283
   done <<< "$(/sbin/zfs list -H -r -t snapshot $namevolfs)"
285
   done <<< "$($BINZFS list -H -r -t snapshot $namevolfs)"
284 286
   fullreplication
285 287
fi
286 288

  
......
293 295
   while read line
294 296
   do 
295 297
     snapshot2replicate=$(echo $line |echo $line |sed -e "s/ \+/ /g"|cut -d " " -f1)
296
   done <<< "$(/sbin/zfs list -H -r -t snapshot $namevolfs)"
298
   done <<< "$($BINZFS list -H -r -t snapshot $namevolfs)"
297 299
   fullreplication
298 300
fi
299 301

  
......
312 314
       break
313 315
    fi
314 316
    cpt=$cpt+1
315
  done <<< "$(/sbin/zfs list -H -r -t snapshot $namevolfs|tac)"
317
  done <<< "$($BINZFS list -H -r -t snapshot $namevolfs|tac)"
316 318
  lastsnapshot=$(echo $lastsnapshotReplicated |sed -e "s/ \+/ /g"|cut -d " " -f1|cut -d "@" -f2) 
317 319
 
318 320
  if [ "$snaphot2replicate" == "$lastsnapshot" ]
......
321 323
     exit 1
322 324
 
323 325
  fi
324
  check_lastsnapshotReplica=$(ssh -o BatchMode=yes root@$server /sbin/zfs list -H -r -t snapshot $namereplica |grep $lastsnapshot|wc -l)
325
  check_currentsnapshotReplica=$(ssh -o BatchMode=yes root@$server /sbin/zfs list -H -r -t snapshot $namereplica |grep $snaphot2replicate=|wc -l)
326
  check_lastsnapshotReplica=$(ssh -o BatchMode=yes root@$server $BINZFS list -H -r -t snapshot $namereplica |grep $lastsnapshot|wc -l)
327
  check_currentsnapshotReplica=$(ssh -o BatchMode=yes root@$server $BINZFS list -H -r -t snapshot $namereplica |grep $snaphot2replicate=|wc -l)
326 328
  if [[ $check_lastsnapshotReplica -eq 0 ]]
327 329
  then
328 330
     echo "Incoherence, incremental replication failed : $lastsnapshotReplicated is missing" 1>&2

Formats disponibles : Unified diff