From ecd17901ea99621f02c6531d1cdd146666f30ce8 Mon Sep 17 00:00:00 2001
From: "Alan J. Pippin" <ajp@pippins.net>
Date: Fri, 16 Jan 2009 21:44:40 -0700
Subject: [PATCH] Added code to destroy backup markers on local machine if
 replicate aborts

---
 zfs-replicate | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/zfs-replicate b/zfs-replicate
index a082ce3..c7e7c2f 100755
--- a/zfs-replicate
+++ b/zfs-replicate
@@ -36,9 +36,24 @@ cleanup() {
 }
 fatal_and_exit() {
   echo -e 2>&1 "$1"
+  # Destroy the backup markers on the local filesystem if they exist
+  if [[ -n "$current_backup_marker" ]]; then
+    zfs list -t snapshot ${local_pool}/${current_backup_marker} > /dev/null 2>&1
+    if [ $? == 0 ]; then
+      $zfs destroy ${local_pool}/${current_backup_marker}
+    fi
+  fi
+  if [[ -n "$previous_backup_marker" ]]; then
+    zfs list -t snapshot ${local_pool}/${previous_backup_marker} > /dev/null 2>&1 
+    if [ $? == 0 ]; then
+      $zfs destroy ${local_pool}/${previous_backup_marker}
+    fi
+  fi
+  # send email notification
   if [[ -n "$2" ]]; then
     echo -e "$1" | $mailx -s "zfs replicate on $hostname failed" "$2"
   fi
+  # exit
   exit 1
 }
 trap fatal_and_exit INT
-- 
2.34.1