zfs/zynk
author Tomas Zeman <tomas@functionals.cz>
Tue, 15 Dec 2020 09:22:21 +0100
changeset 60 4267602e8494
parent 14 1de92b1b5cf3
permissions -rw-r--r--
fs2json: directory structure -> json object converter. E.g. to be used instead of erica / py-Couchapp (interaction with couchdb is left to the user).

#!/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`"