+ # We didn't find any backup markers, next check to see if we have a common snapshot.
+
+ # 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, incrementally send the new snaps
+ replicate "$zfs send -Rc -I${common/*@/@} ${current_backup_marker}"
+ if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote incremental $zfs send command failed on $hostname" $mailto
+ fi
+ else
+ # We did not find any markers or a common snapshot
+ # At this point, we'll have to send the entire filesystem
+ # Destroy the local filesystem if it exists before receving the full replicate
+ zfs list ${backup_pool}/${remote_fs} > /dev/null 2>&1
+ if [ $? == 0 ]; then
+ if [[ $destroy_local_filesystem_on_full_replicate == 1 ]]; then
+ $zfs destroy -r ${backup_pool}/${remote_fs}
+ if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote full $zfs destroy command failed on $hostname" $mailto
+ fi
+ else
+ echo "-W- We need to destroy a local filesystem before receiving a full stream."
+ echo " However, since the option is set to prevent this, skipping replicate operation."
+ fatal_and_exit "unable to destroy local filesystem:\n$zfs destroy -r ${backup_pool}/${remote_fs} not able to run on $hostname" $mailto
+ fi
+ fi
+ # Send the full filesystem
+ replicate "$zfs send -Rc ${current_backup_marker}"
+ if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote full $zfs send command failed on $hostname" $mailto
+ fi
+ fi
+fi
+
+# destroy the previous backup markers now that we've replicated past them
+# don't check the return codes here because these may not exist, and that is ok
+$zfs destroy ${backup_pool}/${previous_backup_marker} > /dev/null 2>&1
+$ssh $remote $zfs destroy ${previous_backup_marker} > /dev/null 2>&1