Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rate limiting CrashPlan
#!/bin/sh
# The network device used for backups
dev=p10p1
# The remove address of the CrashPlanserver
crashplan_addr=50.93.246.1
# The port
crashplan_port=443
# The rate limit. See tc(8) for acceptable syntax.
crashplan_limit=2mbit
if [ "$1" = "enable" ]; then
#
# This creates and activates the traffic shaper
# configuration.
#
logger -s -t ratelimit -p user.notice "enabling rate limits"
tc qdisc del dev $dev root > /dev/null 2>&1
tc qdisc add dev $dev root handle 1: htb
tc class add dev $dev parent 1: classid 1:10 htb rate $crashplan_limit
tc filter add dev $dev parent 1: prio 0 protocol ip handle 10 fw flowid 1:10
iptables -t mangle -A OUTPUT -d $crashplan_addr -p tcp --dport $crashplan_port -j MARK --set-mark 10
elif [ "$1" = "disable" ]; then
#
# This removes the traffic shaper
# configuration.
#
logger -s -t ratelimit -p user.notice "disabling rate limits"
tc qdisc del dev $dev root > /dev/null 2>&1
iptables -t mangle -D OUTPUT -d $crashplan_addr -p tcp --dport $crashplan_port -j MARK --set-mark 10
elif [ "$1" = "show" ]; then
#
# Shows the current traffic shaper configuration.
#
tc qdisc show dev $dev
tc class show dev $dev
tc filter show dev $dev
iptables -t mangle -vnL OUTPUT
fi
@tianchaijz

This comment has been minimized.

Show comment
Hide comment
@tianchaijz

tianchaijz Feb 4, 2015

Hi lars:

I have doubts on this snippet and I have asked a question on serverfault in detailed, Can you explain my doubts?

Thanks.

tianchaijz commented Feb 4, 2015

Hi lars:

I have doubts on this snippet and I have asked a question on serverfault in detailed, Can you explain my doubts?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment