How to Limit/throttle rsync transfer speed in Linux

If you use the rsync utility to keep your backups synchronized between your servers or with a local machine, you might want to prevent the script from using too much bandwidth. However, rsync makes a lot of network I/O. The point of limiting bandwidth is to make sure your backup scripts don’t clog up the network connection.

Naturally, limiting the amount of bandwidth your backups are using is going to make them happen more slowly, but if you can deal with that, this is the way to do it.

Here is a normal rsync command:

$ rsync –avz -e 'ssh' /path/to/source user@remotehost:/path/to/dest/

What you’ll want to do is use the –bwlimit parameter with a KB/second value, like this:

$ rsync –bwlimit=[kb/second] –avz -e 'ssh' /path/to/source user@remotehost:/path/to/dest/

So if you wanted to limit transfer to around 10000KB/s (9.7MB/s), enter:

$ rsync –bwlimit=10000 –avz -e 'ssh' /path/to/source user@remotehost:/path/to/dest/

Here is a real world example:

rsync –bwlimit=10000 –avz -e 'ssh' /backup/ root@192.168.0.51:/backup/

Here, rsync will be throttled to a bandwidth of 10000kb/second or 9.7MB/s approximately.

Using trickle

There is an alternative to the -bwlimit option. You can also use the “trickle” command to limit the bandwidth of any application you run. The syntax of trickle command is:

$ trickle -u|-d [uploadLimit|downloadLimit] [app]

Here,
-u uploadLimit -> limits the upload bandwidth
-d downloadLimit -> limits the download bandwidth
app -> is the application you want to limit bandwidth for e.g. rsync.

So in our case, we will limit the rsync command bandwidth usage to 0000kb/second using the below commands:

$ trickle -s -u 10000 -d 10000 rsync –avz -e 'ssh' /backup/ root@192.168.0.51:/backup/
Related Post