Ignore:
Timestamp:
09/12/13 07:08:56 (11 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2
Children:
03c14f8
Parents:
651bd28
Message:

Update to lpreserver backend:

Added new "replicate init <dataset>" option, which will re-init the remote side of the replication server, cleaning up any corrupt datasets and preparing to sync fresh again.

Also added a check during replication, we won't try to kickoff a second replication task if a previous one is still running, to avoid collisions. In addition we will not delete any snapshots until the initial replication is finished, in order to prevent undercutting the active replication

File:
1 edited

Legend:

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

    r59f367e rc0e6494  
    257257  if [ "$2" = "sync" -a "$REPTIME" != "sync" ] ; then return 0; fi 
    258258 
     259  # Doing a replication task, check if one is in progress 
     260  export pidFile="${DBDIR}/.reptask-`echo ${LDATA} | sed 's|/|-|g'`" 
     261  if [ -e "${pidFile}" ] ; then 
     262     pgrep -F ${pidFile} >/dev/null 2>/dev/null 
     263     if [ $? -eq 0 ] ; then 
     264        echo_log "Skipped replication on $LDATA, previous replication is still running." 
     265        return 0 
     266     else 
     267        rm ${pidFile} 
     268     fi 
     269  fi 
     270 
     271  # Save this PID 
     272  echo "$$" > ${pidFile} 
     273 
    259274  # Is this a sync-task we do at the time of a snapshot? 
    260275  if [ "$2" = "sync" -a "$REPTIME" = "sync" ] ; then 
     
    286301  if [ "$lastSEND" = "$lastSNAP" ] ; then 
    287302     queue_msg "`date`: Last snapshot $lastSNAP is already marked as replicated!" 
     303     rm ${pidFile} 
    288304     return 1 
    289305  fi 
     
    332348  fi 
    333349 
     350  rm ${pidFile} 
    334351  return $zStatus 
    335352} 
     
    552569   exit $? 
    553570} 
     571 
     572init_rep_task() { 
     573 
     574  LDATA="$1" 
     575 
     576  repLine=`cat ${REPCONF} | grep "^${LDATA}:"` 
     577  if [ -z "$repLine" ] ; then return 0; fi 
     578  
     579  # We have a replication task for this set, get some vars 
     580  hName=`hostname` 
     581  REPHOST=`echo $repLine | cut -d ':' -f 3` 
     582  REPUSER=`echo $repLine | cut -d ':' -f 4` 
     583  REPPORT=`echo $repLine | cut -d ':' -f 5` 
     584  REPRDATA=`echo $repLine | cut -d ':' -f 6` 
     585 
     586  # First check if we even have a dataset on the remote 
     587  ssh -p ${REPPORT} ${REPUSER}@${REPHOST} zfs list ${REPRDATA}/${hName} 2>/dev/null >/dev/null 
     588  if [ $? -eq 0 ] ; then 
     589     # Lets cleanup the remote side 
     590     echo "Removing remote dataset: ${REPRDATA}/${hName}" 
     591     ssh -p ${REPPORT} ${REPUSER}@${REPHOST} zfs destroy -r ${REPRDATA}/${hName} 
     592     if [ $? -ne 0 ] ; then 
     593        echo "Warning: Could not delete remote dataset ${REPRDATA}/${hName}" 
     594     fi 
     595  fi 
     596 
     597  # Now lets mark none of our datasets as replicated 
     598  lastSEND=`zfs get -r backup:lpreserver ${LDATA} | grep LATEST | awk '{$1=$1}1' OFS=" " | tail -1 | cut -d '@' -f 2 | cut -d ' ' -f 1` 
     599  if [ -n "$lastSEND" ] ; then 
     600     zfs set backup:lpreserver=' ' ${LDATA}@$lastSEND 
     601  fi 
     602 
     603} 
Note: See TracChangeset for help on using the changeset viewer.