How can I limit a cpu usage to my backup script. It does a mysql db dump and backup of my www directory then bzip2 everything, but it takes a bit and during this time a cpu has 100% load. Can I somehow limit a cpu to i.e. 25@ at most, it will take a more time to make a backup but won't halt other background processes.
You don't want to limit its CPU usage by percentt - after all, if the CPU has nothing else to do, it might as well dedicate 100% to your script.
You want to make sure other programs have priority over your backup script. To do this, just invoke the script using
This will run the script with low priority, that way it will only get the CPU if other processes are idle.
Often with backup scripts the bottleneck is not CPU but disk I/O. If this is the case, nice will make little difference to the load on your system. iostat, which is included with SYSSTAT, can help you investigate further. Also, this post details other I/O utilities.
ionice might help some. However, ionice will only work with the CFQ scheduler. CFQ became the default with > Linux 2.6.18. RHEL4 provides the 2.6.9 kernel, however it is still default on RHEL4 and newer.