From 9b4efb6762c781618501931ca95c82c598a51df1 Mon Sep 17 00:00:00 2001 From: Joseph Mingrone Date: Sun, 4 Jul 2021 00:33:37 -0300 Subject: [PATCH 1/2] Add support for a separate remote filter (issue #20) --- zap | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/zap b/zap index 9ae946e..3798912 100755 --- a/zap +++ b/zap @@ -386,11 +386,6 @@ rep_full() { else warn "Failed to replicate $lsnap to $sshto:$rloc" fi else # replicating remotely - if [ -n "$v_opt" ]; then - printf "zfs send -Lep s %s " "$C_opt" "$lsnap" - if [ -n "$ZAP_FILTER" ]; then echo "| $ZAP_FILTER "; fi - echo "| ssh $sshto \"sh -c 'zfs recv -Fu $v_opt -d $rloc'\"" - fi if rsend "-Lep $C_opt $lsnap" "zfs recv -Fu $v_opt -d $rloc'"; then [ -n "$v_opt" ] && \ echo "zfs bookmark $lsnap $(echo "$lsnap" | sed 's/@/#/')" @@ -454,11 +449,6 @@ $rloc" else warn "Failed to replicate $lsnap to $sshto:$rloc." fi else # replicate remotely - if [ -n "$v_opt" ]; then - printf "zfs send -Le %s %s %s %s " "$C_opt" "$i" "$sp" "$lsnap " - if [ -n "$ZAP_FILTER" ]; then printf "| %s " "$ZAP_FILTER"; fi - echo "| ssh $sshto \"sh -c 'zfs recv -du $F_opt $v_opt $rloc'\"" - fi if rsend "-Le $C_opt $i $sp $lsnap" "zfs recv -du $F_opt $v_opt $rloc"; then [ -n "$v_opt" ] && \ echo "zfs bookmark $lsnap $(echo "$lsnap" | sed 's/@/#/')" @@ -521,9 +511,28 @@ $sshto:$rloc/$fs was not created by zap." } rsend() { - if [ -n "$ZAP_FILTER" ]; then - zfs send $1 | $ZAP_FILTER | ssh "$sshto" "sh -c '$ZAP_FILTER | $2'" - else + if [ -n "$ZAP_FILTER" ] || [ -n "$ZAP_FILTER_REMOTE" ]; then + if [ -n "$ZAP_FILTER" ]; then + if [ -z "$ZAP_FILTER_REMOTE" ]; then # Only ZAP_FILTER is set + ZAP_FILTER_REMOTE="$ZAP_FILTER" + fi + if [ -n "$v_opt" ]; then + printf "zfs send %s | %s | ssh %s sh -c '%s | %s'\\n" \ + "$1" "$ZAP_FILTER" "$sshto" "$ZAP_FILTER_REMOTE" "$2" + else + fi + zfs send $1 | $ZAP_FILTER | ssh "$sshto" "sh -c '$ZAP_FILTER_REMOTE | $2'" + else # Only ZAP_FILTER_REMOTE is set + if [ -n "$v_opt" ]; then + printf "zfs send %s | ssh %s sh -c '%s | %s'\\n" "$1" "$sshto" \ + "$ZAP_FILTER_REMOTE" "$2" + fi + zfs send $1 | ssh "$sshto" "sh -c '$ZAP_FILTER_REMOTE | $2'" + fi + else + if [ -n "$v_opt" ]; then + printf "zfs send %s | ssh %s sh -c '%s'\\n" "$1" "$sshto" "$2" + fi zfs send $1 | ssh "$sshto" "sh -c '$2'" fi } From 9ee250215390c928637c30a4c291901ecb684e7a Mon Sep 17 00:00:00 2001 From: Joseph Mingrone Date: Sat, 24 Jul 2021 23:07:17 -0300 Subject: [PATCH 2/2] Remove extra 'else' --- zap | 1 - 1 file changed, 1 deletion(-) diff --git a/zap b/zap index 3798912..1d6cafd 100755 --- a/zap +++ b/zap @@ -519,7 +519,6 @@ rsend() { if [ -n "$v_opt" ]; then printf "zfs send %s | %s | ssh %s sh -c '%s | %s'\\n" \ "$1" "$ZAP_FILTER" "$sshto" "$ZAP_FILTER_REMOTE" "$2" - else fi zfs send $1 | $ZAP_FILTER | ssh "$sshto" "sh -c '$ZAP_FILTER_REMOTE | $2'" else # Only ZAP_FILTER_REMOTE is set