在bash脚本( after a命令已经启动)期间运行动态流量整形的解决方案是什么?这有可能吗?
我的用例是,我让rsync在一组磁盘上运行到一个远程备份位置,这在因特网上花费了许多小时,所以我希望将流量整形应用到调用rsync的行,但只在指定的时间内。
例如,目前的计划是在上午5时至上午10时和下午3时至9时将上传量减少到每秒1000 is (1.0MB/s)。
我已经看过--bwlimit=1000 for rsync,但是它在运行的整个时间内都是rsync的形状,not只是所需的成形时间框架。
一旦rsync启动,是否有可能减慢它的速度?因为如果这是可能的,那就是我的解决方案。
我见过有人建议wondershaper,但我想知道这是否可以通过编程“打开或关闭”呢?如果是的话,怎么做?
下面是我使用Stackoverflow慷慨捐款进行的一个模拟,它提供了指定和检查时间计划的功能(基于时间,这对我目前的需要来说还可以).
#!/bin/bash
declare -A shapingTimes
declare -A keycount
useTrafficShaping=1
# schedule
shapingTimes=([0-from]=5 [0-to]=10) # 5am to 10am
shapingTimes+=([1-from]=15 [1-to]=21) # 3pm to 9pm
# because keys and array content differs in order from the way they are defined, we need to tidy this up by setting up the shaping times order in the way in which it is defined above
# to do this, count how many keys used in array entry (https://stackoverflow.com/questions/63532910)
# we use this result to to dynamically calculate the total number of entries ($totalshapingTimes)
for i in "${!shapingTimes[@]}"; do keycount[${i//[0-9]-/}]=""; done
totalshapingTimes=$((${#shapingTimes[*]} / ${#keycount[@]}))
x=1; while [[ $x -le "$totalshapingTimes" ]]; do shapingTimes_order+="$(( x-1 )) "; x=$(( $x + 1 )); done
# 'shapingTimes_order' array is used later in this script to process which shapingTimes are handled in what order
if [[ -n $useTrafficShaping ]] && [[ $useTrafficShaping == 1 ]]; then
echo "Traffic shaping: ON"
# get current time (hour) to determine if we're inside peak times
currentHour=$(date +%H)
# display our traffic shaping time windows as defined in above array
echo "Defined schedule:"
for i in ${shapingTimes_order[*]}; do
echo "${shapingTimes[$i-from]}hrs to ${shapingTimes[$i-to]}hrs"
# work out which peak times we're using, thanks to the help of Glenn Jackman (https://stackoverflow.com/questions/18128573)
if (( ${shapingTimes[$i-from]} <= 10#$currentHour && 10#$currentHour < ${shapingTimes[$i-to]} )); then
# current time matches a specified shaping timeframe, so rsync should go SLOW!
shape=1
fi
done
echo "The current hour is $currentHour"
if [[ -z $shape ]]; then
echo "Not in a shaping window, rsync can run as normal."
# some command here, run rsync as normal
else
echo "Matches a shaping schedule. *** SHAPING NETWORK TRAFFIC ***"
# command here to kick in traffic shaping
fi
else
echo "Traffic shaping: OFF"
# run rsync as normal
fi发布于 2020-09-01 22:25:43
rsync不能动态改变其带宽限制参数。不管你怎么做
例如
rsync a b c d e target:/dir/
to
rsync --bw-limit=bw1 a target:/dir/
...
rsync --bw-limit=bw2 e target:/dir/--time-limit=MINS <>选项如果文件是同步的,rsync是智能的,不会重做它刚才做的事情,所以您可以使用bw限制bw1运行1小时,然后用bw2等重新启动它(如果需要的话暂停它),或者与上面的解决方案结合。
rsync --bw-limit=bw1 --time-limit=60 ...
rsync --bw-limit=bw2 --time-limit=60 ...如果您喜欢,rsync是开放源代码的,您可以添加一些代码来动态地对某些信号(信号和杀掉)进行rsync应答,这些信号将改变内部选项(maight还必须根据代码更改目标rsync守护进程)。
rsync --my-new-version ...
kill -SIGNALTOSLOW rsyncpid
...
kill -SIGNALTOSPEED rsyncpidhttps://serverfault.com/questions/1032336
复制相似问题