Linux – Limit tar read speed

diskiolinuxtar

I'm using tar do make backups of a machine. But, it is using a lot of I/O and slows down the whole machine.

So, is there a way to limit the read speed of tar?

I know about pv, but it limit only the write speed. Because I do incremental backups with tar --listed-incremental, this will work only with the first full backup (subsequent incremental backups will then consume a lot of read I/O if there is only small changes).

I've tried to lower the overall priority of the backup with a combination of nice and ionice, but this not really change anything.

Informations: it's Debian 9 machine, and the files are residing on an ext4 file-system on top of a LVM volume.

Best Answer

You can run your tar command using ionice. Like this:

ionice -c3 tar --listed-incremental [...]

This will let the tar process only do I/O when there is no other process waiting for I/O.

In Debian the ionice utility is in the package util-linux, so you you may need to install that first.

Like with the normal (cpu) nice utility, the I/O scheduler class of a process is inherited by its child processes. When I'm planning to do resource-heavy stuff, I do not want users have their I/O slowed down because of it. I often start my shell this way:

nice ionice -c3 bash

Then everything I do from that shell will be very, very nice :)