-if [ $nodstsnaps == 0 ]; then
- zfs list -rH -t snapshot $srcfs | grep "$srcfs@" | awk '{print $1}' > /tmp/source-list
- zfs list -rH -t snapshot $dstfs | grep "$dstfs@" | sed "s,$dstpool/,," | awk '{print $1}' > /tmp/destination-list
- diff -u /tmp/source-list /tmp/destination-list | grep -v '^+++' | awk '/^\+/ {print}' | sed "s,^\+,$dstpool/," > /tmp/obsolete-snapshots
- rm -f /tmp/source-list /tmp/destination-list
-
- echo >&2 "Removing obsolete backups from the destination pool"
- for snapshot in $(cat /tmp/obsolete-snapshots); do
- echo >&2 "Removing '$snapshot' from destination."
- [ $test == 0 ] && zfs destroy "$snapshot"
- done
-
- echo >&2 "Rolling back to the most recent snapshot on the destination."
- [ $test == 0 ] && zfs rollback $(zfs list -rH -t snapshot $dstfs | grep "$dstfs@" | awk '{snap=$1} END {print snap}')
-
- echo >&2 "Calculating the most recent common snapshot between the two filesystems."
- if zfs list -H "$dstfs" > /dev/null 2>&1; then
- for snap in $(zfs list -rH -t snapshot "$dstfs" | grep "$dstfs@" |
- sed 's,.*@,,' | awk '{print$1}'); do
- if zfs list -rH -t snapshot "$fs" | grep "$fs@" | sed 's,.*@,,' | awk '{print$1}' | grep "^${snap}$" >/dev/null 2>&1; then
- common=$snap
- fi
- done
- fi
-fi
-
-base=$common
-foundcommon=false
-if [ -z "$common" ]; then
- foundcommon=true
-fi
-
-for snap in $(zfs list -rH -t snapshot "$fs" | grep "$fs@" |
- sed 's,.*@,,' | awk '{print$1}'); do
- if [ "$snap" = "$common" ]; then
- foundcommon=true
- continue
- fi
-
- if $foundcommon; then
- if [ -z "$base" ]; then
- echo >&2 "Sending '$fs@$snap'"
- [ $test == 0 ] && zfs set readonly=on "$dstpool"
- [ $test == 0 ] && zfs set atime=off "$dstpool"
- [ $test == 0 ] && zfs set sharenfs=off "$dstpool"
- [ $test == 0 ] && zfs set mountpoint=legacy "$dstpool"
- [ $test == 0 ] && zfs send "$fs@$snap" | zfs recv -v "$dstfs"
- else
- echo >&2 "Sending '$fs@$base' -> '$fs@$snap'"
- [ $test == 0 ] && zfs send -i "$fs@$base" "$fs@$snap" | zfs recv -v "$dstfs"
- fi
- base=$snap
- fi
-done
-
-true