From a44c3f17def4addd4be08f31b934afa9c4ce0a8d Mon Sep 17 00:00:00 2001
From: "Alan J. Pippin" <alan@pippins.net>
Date: Sun, 23 Aug 2020 18:21:42 -0600
Subject: [PATCH] Return non-zero exit code if any command in pipe fails

Change-Id: I463e7afc7ee01a352558194eabbac67c9446b106
---
 zfs-replicate | 4 ++++
 zfs-restore   | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/zfs-replicate b/zfs-replicate
index 02f9924..7f205e2 100755
--- a/zfs-replicate
+++ b/zfs-replicate
@@ -18,6 +18,9 @@ remote=$1
 remote_fs=$2
 remote_pool=${2%%/*}
 
+# return non-zero exit code if any command in the pipe fails
+set -o pipefail
+
 # get the backup pool from the command line or the config file if not specified
 if [[ -n $3 ]]; then
     backup_pool=$3
@@ -264,6 +267,7 @@ fi
 # 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
+sleep 1
 
 # Rename the current backup marker to be the previous backup marker
 $zfs rename ${backup_pool}/${current_backup_marker} ${backup_pool}/${previous_backup_marker}
diff --git a/zfs-restore b/zfs-restore
index 4014ff7..d5ca2e6 100755
--- a/zfs-restore
+++ b/zfs-restore
@@ -16,6 +16,9 @@ dst_pool=$3
 dst_fs=$4
 dst_hostname=$5
 
+# return non-zero exit code if any command in the pipe fails
+set -o pipefail
+
 if [[ -z "$SCRIPT_UNDER_TEST" ]]; then
     exec >> $logdir/zfs-restore.log 2>&1
 fi
-- 
2.34.1