From d41208cdfe82d71cac4b3e4ca2110adf2343f722 Mon Sep 17 00:00:00 2001 From: Otho Date: Mon, 16 Jan 2023 22:18:27 -0500 Subject: [PATCH] Implemented new run approach. --- backup.sh | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/backup.sh b/backup.sh index 713ff1c..251fe91 100755 --- a/backup.sh +++ b/backup.sh @@ -39,6 +39,15 @@ debug() fi } +run_send_recv() +{ + if [ $ZB_TEST_MODE = "TRUE" ]; then + echo "$send_cmd | $pv_cmd | $recv_cmd" + else + $send_cmd | $pv_cmd | $recv_cmd + fi +} + set_compression() { case $SEND_COMPRESSED in [tTyY]*) ZFS_SEND_OPTS="$ZFS_SEND_OPTS -c" @@ -151,17 +160,16 @@ zfs_allow_mirrors() *) zroot="$zroot/" ;; esac fi - run_cmd=" + remote_cmd=" for dataset in $SEND_DATASETS; do dataset=`echo \\$dataset|cut -d: -f2` zfs allow -u $user $MIRROR_PERMS $zroot\$dataset done " if [ $ZB_TEST_MODE = "TRUE" ]; then - echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $run_cmd - + echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $remote_cmd else - ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $run_cmd + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $remote_cmd fi done < sendnodes.tmp } @@ -193,18 +201,13 @@ send_latest() dataset=`echo $dataset|cut -d: -f1` debug "Processing $dataset (remote $remote_dataset)." origin_snapshot=`get_latest_snapshot $dataset` - run_cmd=" - zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot | - pv -qL ${speed:-$DEF_SPEED} | - ssh $SSH_SEND_OPTS -o port=$ssh_port \ - $user@$addr \ + send_cmd="zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot" + pv_cmd="pv -qL ${speed:-$DEF_SPEED}" + recv_cmd=" + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset - " - if [ $ZB_TEST_MODE = "TRUE" ]; then - echo $run_cmd - else - $run_cmd - fi + " + run_send_recv done done < sendnodes.tmp } @@ -224,19 +227,16 @@ send_increment() dataset=`echo $dataset|cut -d: -f1` origin_snapshot=`get_latest_snapshot` remote_snapshot=`get_latest_remote_snapshot` - run_cmd=" - zfs send $ZFS_SEND_OPTS \ - -i $dataset@$remote_snapshot \ - $dataset@$origin_snapshot | - pv -qL ${speed:-$DEF_SPEED} | - ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ - zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset + send_cmd=" + zfs send $ZFS_SEND_OPTS -i $dataset@$remote_snapshot \ + $dataset@$origin_snapshot " - if [ $ZB_TEST_MODE = "TRUE" ]; then - echo $run_cmd - else - $run_cmd - fi + pv_cmd="pv -qL ${speed:-$DEF_SPEED}" + recv_cmd=" + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ + zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset + " + run_send_recv done done < sendnodes.tmp }