+ # 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
+ if [[ $throttle_enable == 1 && -e $throttle ]]; then
+ ssh $remote $zfs send -R -I${common/*@/@} ${current_backup_marker} |
+ $throttle $throttle_opt | $zfs receive -vF -d ${local_pool}/${remote_pool}
+ else
+ ssh $remote $zfs send -R -I${common/*@/@} ${current_backup_marker} |
+ $zfs receive -vF -d ${local_pool}/${remote_pool}
+ fi
+ if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote incremental $zfs send command failed" $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 ${local_pool}/${remote_fs} > /dev/null 2>&1
+ if [ $? == 0 ]; then
+ if [[ $destroy_local_filesystem_on_full_replicate == 1 ]]; then
+ $zfs destroy -r ${local_pool}/${remote_fs}
+ if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote full $zfs destroy command failed" $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 ${local_pool}/${remote_fs} not able to run" $mailto
+ fi
+ fi
+ # Send the full filesystem
+ if [[ $throttle_enable == 1 && -e $throttle ]]; then
+ ssh $remote $zfs send -R ${current_backup_marker} |
+ $throttle $throttle_opt | $zfs receive -vF -d ${local_pool}/${remote_pool}
+ else
+ ssh $remote $zfs send -R ${current_backup_marker} |
+ $zfs receive -vF -d ${local_pool}/${remote_pool}
+ fi
+ if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote full $zfs send command failed" $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 ${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
+ fatal_and_exit "-E- local $zfs rename command failed" $mailto
+fi
+ssh $remote $zfs rename ${current_backup_marker} ${previous_backup_marker}
+if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote $zfs rename command failed" $mailto
+fi