-
- 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"
+ # Now it should be safe to send the snaps
+ ssh $remote $zfs send -R -I${previous_backup_marker} ${current_backup_marker} |
+ $zfs receive -vF -d ${local_pool}/${remote_pool}
+ if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote incremental $zfs send command failed" $mailto
+ fi
+else
+ # 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
+ ssh $remote $zfs send -R -I${common/*@/@} ${current_backup_marker} |
+ $zfs receive -vF -d ${local_pool}/${remote_pool}
+ 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
+ ssh $remote $zfs send -R ${current_backup_marker} |
+ $zfs receive -vF -d ${local_pool}/${remote_pool}
+ if [ $? != 0 ]; then
+ fatal_and_exit "-E- remote full $zfs send command failed" $mailto