Changeset 9c74d02


Ignore:
Timestamp:
05/09/14 14:46:00 (13 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, releng/10.0.2, releng/10.0.3, releng/10.1, releng/10.1.1, releng/10.1.2
Children:
b477abc
Parents:
00059ce
Message:

Fix some bugs running replication sync tasks on a particular dataset

Location:
src-sh/lpreserver
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src-sh/lpreserver/backend/functions.sh

    r49942f24 r9c74d02  
    238238  if [ ! -e "$REPCONF" ] ; then return 0; fi 
    239239 
    240   ret=0 
    241   for repLine in `cat ${REPCONF} | grep "^${1}:"` 
    242   do 
    243  
    244     # We have a replication task for this dataset, lets check if we need to do it now 
    245     LDATA="$1" 
    246     REPTIME=`echo $repLine | cut -d ':' -f 2` 
    247  
    248     # Export the replication variables we will be using 
    249     export REPHOST=`echo $repLine | cut -d ':' -f 3` 
    250     export REPUSER=`echo $repLine | cut -d ':' -f 4` 
    251     export REPPORT=`echo $repLine | cut -d ':' -f 5` 
    252     export REPRDATA=`echo $repLine | cut -d ':' -f 6` 
    253  
    254     if [ "$2" = "force" ] ; then 
    255        # Ready to do a forced replication 
    256        export DIDREP=1 
    257        echo_log "Starting replication MANUAL task on ${DATASET}: ${REPLOGSEND}" 
    258        queue_msg "`date`: Starting replication MANUAL task on ${DATASET}\n" 
    259        start_rep_task "$LDATA" "$REPHOST" 
    260        if [ $? -ne 0 ] ; then ret=1; fi 
    261        continue 
    262     fi 
    263  
    264     # If we are checking for a sync task, and the rep isn't marked as sync we can continue 
    265     if [ "$2" = "sync" -a "$REPTIME" != "sync" ] ; then continue; fi 
    266  
    267     # Doing a replication task, check if one is in progress 
    268     export pidFile="${DBDIR}/.reptask-`echo ${LDATA} | sed 's|/|-|g'`" 
    269     if [ -e "${pidFile}" ] ; then 
    270        pgrep -F ${pidFile} >/dev/null 2>/dev/null 
    271        if [ $? -eq 0 ] ; then 
    272           echo_log "Skipped replication on $LDATA, previous replication is still running." 
    273           continue 
    274        else 
    275           rm ${pidFile} 
    276        fi 
    277     fi 
    278  
    279     # Save this PID 
    280     echo "$$" > ${pidFile} 
    281  
    282     # Is this a sync-task we do at the time of a snapshot? 
    283     if [ "$2" = "sync" -a "$REPTIME" = "sync" ] ; then 
    284        export DIDREP=1 
    285        echo_log "Starting replication SYNC task on ${DATASET}: ${REPLOGSEND}" 
    286        queue_msg "`date`: Starting replication SYNC task on ${DATASET}\n" 
    287        start_rep_task "$LDATA" 
    288        if [ $? -ne 0 ] ; then ret=1; fi 
    289        continue 
    290     else 
    291        # Ready to do a scheduled replication 
    292        export DIDREP=1 
    293        echo_log "Starting replication SCHEDULED task on ${DATASET}: ${REPLOGSEND}" 
    294        queue_msg "`date`: Starting replication SCHEDULED task on ${DATASET}\n" 
    295        start_rep_task "$LDATA" 
    296        if [ $? -ne 0 ] ; then ret=1; fi 
    297        continue 
    298     fi 
    299   done 
    300   return $ret 
     240  # Are we running as a sync task, or to a particular host? 
     241  if [ "$2" = "sync" ] ; then 
     242    repLine=`cat ${REPCONF} | grep "^${1}:${2}:" | head -n 1` 
     243  else 
     244    repLine=`cat ${REPCONF} | grep "^${1}:.*:${2}:"` 
     245  fi 
     246 
     247  if [ -z "$repLine" ] ; then return 0 ; fi 
     248 
     249  # We have a replication task for this dataset, lets check if we need to do it now 
     250  LDATA="$1" 
     251  REPTIME=`echo $repLine | cut -d ':' -f 2` 
     252 
     253  # Export the replication variables we will be using 
     254  export REPHOST=`echo $repLine | cut -d ':' -f 3` 
     255  export REPUSER=`echo $repLine | cut -d ':' -f 4` 
     256  export REPPORT=`echo $repLine | cut -d ':' -f 5` 
     257  export REPRDATA=`echo $repLine | cut -d ':' -f 6` 
     258 
     259  # If we are checking for a sync task, and the rep isn't marked as sync we can continue 
     260  if [ "$2" = "sync" -a "$REPTIME" != "sync" ] ; then continue; fi 
     261 
     262  # Doing a replication task, check if one is in progress 
     263  export pidFile="${DBDIR}/.reptask-`echo ${LDATA} | sed 's|/|-|g'`" 
     264  if [ -e "${pidFile}" ] ; then 
     265     pgrep -F ${pidFile} >/dev/null 2>/dev/null 
     266     if [ $? -eq 0 ] ; then 
     267        echo_log "Skipped replication on $LDATA, previous replication is still running." 
     268        return 1 
     269     else 
     270        rm ${pidFile} 
     271     fi 
     272  fi 
     273 
     274  # Save this PID 
     275  echo "$$" > ${pidFile} 
     276 
     277  # Is this a sync-task we do at the time of a snapshot? 
     278  if [ "$2" = "sync" -a "$REPTIME" = "sync" ] ; then 
     279     export DIDREP=1 
     280     echo_log "Starting replication SYNC task on ${DATASET}: ${REPLOGSEND}" 
     281     queue_msg "`date`: Starting replication SYNC task on ${DATASET}\n" 
     282     start_rep_task "$LDATA" 
     283     return $? 
     284  else 
     285     # Ready to do a scheduled replication 
     286     export DIDREP=1 
     287     echo_log "Starting replication SCHEDULED task on ${DATASET}: ${REPLOGSEND}" 
     288     queue_msg "`date`: Starting replication SCHEDULED task on ${DATASET}\n" 
     289     start_rep_task "$LDATA" 
     290     return $? 
     291  fi 
    301292} 
    302293 
  • src-sh/lpreserver/backend/runrep.sh

    re0a6855 r9c74d02  
    1111 
    1212DATASET="${1}" 
    13 TIME="${2}" 
    14 rHost="${3}" 
     13rHost="${2}" 
    1514 
    1615if [ -z "${DATASET}" ]; then 
    1716  exit_err "No dataset specified!" 
    1817fi 
     18if [ -z "${rHost}" ]; then 
     19  exit_err "No target host specified!" 
     20fi 
    1921 
    20 check_rep_task "$DATASET" "$TIME" "$rHost" 
     22check_rep_task "$DATASET" "$rHost" 
    2123status=$? 
    2224 
  • src-sh/lpreserver/backend/zfsmksnap.sh

    r69265de r9c74d02  
    2323fi 
    2424 
    25 REPLICATE="${3}" 
    26  
    2725# Make the snapshot now 
    2826snapStat=0 
     
    4745   email_msg "Success - Manual Snapshot" "`echo_queue_msg`" 
    4846fi 
    49  
    50  
    51  
    52 # Check if we need to run a replication task for this dataset 
    53 if [ "$REPLICATE" = "YES" ] ; then 
    54   ${PROGDIR}/backend/runrep.sh ${DATASET} force 
    55 fi 
  • src-sh/lpreserver/lpreserver

    r49942f24 r9c74d02  
    383383 echo "Help mksnap 
    384384 
    385 Create a new ZFS snapshot of a dataset and optionally replicate it immediately 
    386  
    387 Usage: 
    388  
    389   lpreserver mksnap --replicate <dataset> <snapshotname> 
     385Create a new ZFS snapshot of a dataset 
     386 
     387Usage: 
     388 
     389  lpreserver mksnap <dataset> <snapshotname> 
    390390 
    391391Example: 
     
    395395  or 
    396396 
    397   lpreserver mksnap --replicate tank1/usr/home/kris mysnapshot 
     397  lpreserver mksnap tank1/usr/home/kris mysnapshot 
    398398 
    399399NOTE: 
     
    495495 
    496496   mksnap) require_root 
    497          if [ "$2" = "--replicate" ] ; then 
    498            REP="YES" 
    499            DATASET="$3" 
    500            SNAPNAME="$4" 
    501          else 
    502            REP="NO" 
    503            DATASET="$2" 
    504            SNAPNAME="$3" 
    505          fi 
    506          ${PROGDIR}/backend/zfsmksnap.sh "${DATASET}" "$SNAPNAME" "$REP" 
     497         DATASET="$2" 
     498         SNAPNAME="$3" 
     499         ${PROGDIR}/backend/zfsmksnap.sh "${DATASET}" "$SNAPNAME" 
    507500         ;; 
    508501 
Note: See TracChangeset for help on using the changeset viewer.