#/bin/bash set -x # Usage: replicate remote=$1 remote_fs=$2 # The ssh connection doesn't find zfs without this. zfs=/usr/sbin/zfs # List the snapshots on the remote machine. remote_list=$(mktemp /tmp/replicate.XXXXXX) ssh $remote \ $zfs list -H -t snapshot | grep ^${remote_fs}@ | awk '{print$1}' > $remote_list # List the snapshots on the local machine. local_list=$(mktemp /tmp/replicate.XXXXXX) $zfs list -H -t snapshot | grep ^backups/${remote_fs}@ | awk '{gsub(/^backups./,"",$1); print$1}' > $local_list # See what the most recent snapshot on the remote end is. latest=$(tail -n 1 $remote_list) # I did this to make sure that diff would always display the most recent common echo bogus.remote >> $remote_list echo bogus.local >> $local_list common=$(diff -u $remote_list $local_list | grep '^ ' | tail -n 1) ssh $remote $zfs send -R -I${common/*@/@} $latest | $zfs receive -vF -d backups/${remote_fs%/*} rm -f $local_list $remote_list