From ab3edb1d513f6100cb62ec2ae303fff7e7eb56a5 Mon Sep 17 00:00:00 2001 From: Otho Date: Mon, 16 Jan 2023 22:04:39 -0500 Subject: [PATCH] Changed method for setting up run command. --- backup.sh | 76 +++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/backup.sh b/backup.sh index de9834d..8a24b79 100755 --- a/backup.sh +++ b/backup.sh @@ -98,18 +98,15 @@ list_remote_datasets() { *) zroot="$zroot/" ;; esac fi + run_cmd=" + sh -c 'for dataset in $SEND_DATASETS; do + dataset=`echo \\$dataset|cut -d: -f2` + zfs list -H $zroot\$dataset; + done'" if [ $BG_TEST_MODE = "TRUE" ]; then - echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr\ - "sh -c 'for dataset in $SEND_DATASETS; do - dataset=`echo \\$dataset|cut -d: -f2` - zfs list -H $zroot\$dataset; - done'" + echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $run_cmd else - ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ - "sh -c 'for dataset in $SEND_DATASETS; do - dataset=`echo \\$dataset|cut -d: -f2` - zfs list -H $zroot\$dataset; - done';" + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $run_cmd fi done < sendnodes.tmp } @@ -154,18 +151,17 @@ zfs_allow_mirrors() *) zroot="$zroot/" ;; esac fi + run_cmd=" + for dataset in $SEND_DATASETS; do + dataset=`echo \\$dataset|cut -d: -f2` + zfs allow -u $user $MIRROR_PERMS $zroot\$dataset + done + " if [ $BG_TEST_MODE = "TRUE" ]; then - echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ - "for dataset in $SEND_DATASETS; do - dataset=`echo \\$dataset|cut -d: -f2` - zfs allow -u $user $MIRROR_PERMS $zroot\$dataset - done" + echo ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $run_cmd + else - ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ - "for dataset in $SEND_DATASETS; do - dataset=`echo \\$dataset|cut -d: -f2` - zfs allow -u $user $MIRROR_PERMS $zroot\$dataset - done" + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr $run_cmd fi done < sendnodes.tmp } @@ -197,17 +193,17 @@ send_latest() dataset=`echo $dataset|cut -d: -f1` debug "Processing $dataset (remote $remote_dataset)." origin_snapshot=`get_latest_snapshot $dataset` - if [ $BG_TEST_MODE = "TRUE" ]; then - echo zfs send $ZFS_SEND_OPTS $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 - else + 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 \ - zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset + pv -qL ${speed:-$DEF_SPEED} | + ssh $SSH_SEND_OPTS -o port=$ssh_port \ + $user@$addr \ + zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset + " + if [ $BG_TEST_MODE = "TRUE" ]; then + echo $run_cmd + else + $run_cmd fi done done < sendnodes.tmp @@ -228,20 +224,18 @@ send_increment() dataset=`echo $dataset|cut -d: -f1` origin_snapshot=`get_latest_snapshot` remote_snapshot=`get_latest_remote_snapshot` - if [ $BG_TEST_MODE = "TRUE" ]; then - echo 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 - else + 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 + pv -qL ${speed:-$DEF_SPEED} | + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ + zfs recv $ZFS_RECV_OPTS $zroot$remote_dataset + " + if [ $BG_TEST_MODE = "TRUE" ]; then + echo $run_cmd + else + $run_cmd fi done done < sendnodes.tmp