# HG changeset patch # User Tomas Zeman # Date 1306135932 -7200 # Node ID 1de92b1b5cf3fb9a9e894df61ad4300914a5d1e2 # Parent 28f1b26621eb31a86814d2bd36247a90469d1968 zfs/zynk: ZFS replication script diff -r 28f1b26621eb -r 1de92b1b5cf3 zfs/zynk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zfs/zynk Mon May 23 09:32:12 2011 +0200 @@ -0,0 +1,55 @@ +#!/bin/sh -e +# Based on: http://www.cuddletech.com/blog/pivot/entry.php?id=989 +# +# This script differs from original Zynk that uses -R and destination dataset, +# not filesystem. +# +## ZYNK: The Zuper Zimple ZFS Sync (Replication) Tool +## Form: zynk local/dataset root@remote.host destination/dataset + +# Please note: The reason this is so simple is because there is no error +# checking, reporting, or cleanup. +# +# In the event that something goes wonkey, you'll manually need to fix the +# snapshots and modify or remove the run datafile which contains the most +# recent snapshot name. +# +# Furthermore, this absolutely relies on the GNU version of 'date' in order to +# get epoch time. +# +# Before using, make sure you've: +# 1. distributed your SSH key to the remote host and can ssh without +# password; +# 2. delegated zfs rights to the user performing zynk. +# + +if [ -z "$3" ]; then + echo "Usage: zynk local/dataset remote.host destination/dataset" + exit 1 +fi + +DATE=`date +%s` +if [ "$DATE" = "%s" ]; then + echo "Must use GNU Date, please install and modify script." + exit 2 +fi + +LOCALFS=$1 +HOST=$2 +REMOTEFS=$3 +RUNF=`echo $LOCALFS-$HOST-$REMOTEFS|sed -e 's{[@/]{-{g'` +CUR=`date '+%F-%H%M'` + +TYPE="Full" +SEND_OPTS="" + +if [ -e $RUNF ]; then + TYPE="Incremental" + SEND_OPTS="-i $LOCALFS@`cat $RUNF`" +fi + +echo "$TYPE started at `date`" +zfs snapshot -r $LOCALFS@$CUR +zfs send -v -R $SEND_OPTS $LOCALFS@$CUR | ssh $HOST zfs recv -F -d $REMOTEFS +echo $CUR > $RUNF +echo "$TYPE complete at `date`"