Zfs Replication

I’ve been hacking a like bash code to build a replication offline backup system for zfs. Bit of a rough job, but some people might find it useful. Seems though that the iscsi target in Solaris is in a worse state that I realised, so I might have to reconsider Plan Linux. It would be a shame as being able to do stuff like the below is very nice and creates a whole new level of sysadmin ease.

#!/bin/bash

if [ $# -lt 1 ]; then
  echo "Usage: $0 tank"
  exit 0
fi

TANK=$1
DSTN="tank/sstore"

TIME=`date '+%Y-%m-%d-%H:%M:%S'`
zfs snapshot -r $TANK@$TIME


for  i in `zfs list -H | grep $TIME | cut -f1` ; do
  FS=`echo $i | cut -f1 -d'@'`
  LAST=`ssh ihstore zfs list -Ho backups:lastsend $DSTN/$FS 2> /dev/null`
  if [ $? == 1 ]; then
    echo "New $FS to $i"
    echo "  zfs send          $i | ssh ihstore zfs receive -v -d $DSTN/$TANK"
    zfs send          $i | ssh ihstore zfs receive -v -d $DSTN/$TANK
    ERR=$?
    if [ $ERR != 0 ]; then echo "Error: $ERR for $i"; continue ; fi
    ssh ihstore zfs set backups:lastsend=$i  $DSTN/$FS
    continue
  else
    echo "$FS from $LAST to $i"
    echo "  zfs send -i $LAST $i | ssh ihstore zfs receive -F $DSTN/$i"
    zfs send -i $LAST $i | ssh ihstore zfs receive -v -F $DSTN/$i
    ERR=$?
    if [ $ERR != 0 ]; then echo "Error: $ERR for $i"; continue ; fi
    ssh ihstore zfs set backups:lastsend=$i  $DSTN/$FS
  fi
  echo "  zfs destroy $LAST"
  zfs destroy $LAST
  echo "done: $i"
  echo ""
done 

Comments are closed.