From 4da22952cb2e7e47f948674804d7f43858c359fa Mon Sep 17 00:00:00 2001 From: Otho Date: Mon, 9 Jan 2023 01:35:38 -0500 Subject: [PATCH] Added bandwidth limiter. --- backup.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/backup.sh b/backup.sh index 6aded5b..b812e03 100755 --- a/backup.sh +++ b/backup.sh @@ -21,6 +21,7 @@ ZFS_SEND_OPTS="-vpRLe" ZFS_SNAPSHOT_OPTS="-r" ZFS_RECV_OPTS="-svu" SSH_SEND_OPTS="-Ti ~/.ssh/id_rsa" +BANDWIDTH_LIMIT="100M" read LOCAL_HOST LOCAL_USER LOCAL_PORT LOCAL_TZ SEND_COMPRESSED < $nodes_file case $SEND_COMPRESSED in @@ -163,13 +164,15 @@ send_latest() origin_snapshot=`get_latest_snapshot $dataset` if [ $BG_TEST_MODE = "TRUE" ]; then echo zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot \| \ - ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ - zfs recv $ZFS_RECV_OPTS $zroot$dataset + pv -qL $BANDWIDTH_LIMIT \| \ + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ + zfs recv $ZFS_RECV_OPTS $zroot$dataset else zfs send $ZFS_SEND_OPTS $dataset@$origin_snapshot | - ssh $SSH_SEND_OPTS -o port=$ssh_port \ - $user@$addr \ - zfs recv $ZFS_RECV_OPTS $zroot$dataset + pv -qL $BANDWIDTH_LIMIT | + ssh $SSH_SEND_OPTS -o port=$ssh_port \ + $user@$addr \ + zfs recv $ZFS_RECV_OPTS $zroot$dataset fi done done < sendnodes.tmp @@ -192,14 +195,16 @@ send_increment() echo zfs send $ZFS_SEND_OPTS \ -i $dataset@$remote_snapshot \ $dataset@$origin_snapshot \| \ - ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ - zfs recv $ZFS_RECV_OPTS $zroot$dataset + pv -qL $BANDWIDTH_LIMIT \| \ + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ + zfs recv $ZFS_RECV_OPTS $zroot$dataset else zfs send $ZFS_SEND_OPTS \ -i $dataset@$remote_snapshot \ - $dataset@$origin_snapshot | - ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ - zfs recv $ZFS_RECV_OPTS $zroot$dataset + $dataset@$origin_snapshot | + pv -qL $BANDWIDTH_LIMIT | + ssh $SSH_SEND_OPTS -o port=$ssh_port $user@$addr \ + zfs recv $ZFS_RECV_OPTS $zroot$dataset fi done done < sendnodes.tmp