+
+ # destroy the previous backup markers now that we've replicated past them
+ $zfs destroy ${local_pool}/${previous_backup_marker} > /dev/null 2>&1
+ ssh $remote $zfs destroy ${previous_backup_marker} > /dev/null 2>&1
+
+ # Rename the current backup marker to be the previous backup marker
+ $zfs rename ${local_pool}/${current_backup_marker} ${local_pool}/${previous_backup_marker}
+ if [[ $? != 0 ]]; then
+ echo "-E- local $zfs rename command failed"
+ exit 1
+ fi
+ ssh $remote $zfs rename ${current_backup_marker} ${previous_backup_marker}
+ if [[ $? != 0 ]]; then
+ echo "-E- remote $zfs rename command failed"
+ exit 1
+ fi
+
+else
+ # 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
+ # Since we're keying off the context of the diff, we need to ensure we will get context
+ # by injecting a known difference in case no others exist in the lists.
+ echo bogus.remote >> $remote_list
+ echo bogus.local >> $local_list
+ common=$(diff -u $remote_list $local_list | grep '^ ' | tail -n 1)
+
+ if [ -n "$common" ]; then
+ # We found a common snapshot
+ ssh $remote $zfs send -R -I${common/*@/@} $latest |
+ $zfs receive -vF -d ${local_pool}/${remote_fs%/*}
+ else
+ # We did not find a common snapshot, so send the entire filesystem
+ ssh $remote $zfs send -R $latest |
+ $zfs receive -vF -d ${local_pool}/${remote_fs%/*}
+ fi
+fi
+
+# Remove tmp files
+#rm -f $local_list $remote_list