- 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"
+ # 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 ${backup_pool}/${remote_pool}
+ else
+ $ssh $remote $zfs send -R -I${common/*@/@} ${current_backup_marker} |
+ $zfs receive -vF -d ${backup_pool}/${remote_pool}
+ fi
+ 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
+ if [[ $throttle_enable == 1 && -e $throttle ]]; then
+ $ssh $remote $zfs send -R ${current_backup_marker} |
+ $throttle $throttle_opt | $zfs receive -vF -d ${backup_pool}/${remote_pool}