Reduce CPU and Disk load of backup scripts with nice and ionice

Running a nightly backup script on a server system, such as a web hosting server, can result in a heavy load and longer latency for other processes, for example, HTML or .php pages load slowly during the backup because the backup script requires too many I/O or CPU resources.

On Linux systems, two shell utilities are available to set I/O and CPU scheduling for an application or script. The utilities are named nice and ionice.

Reduce the I/O priority of the /usr/local/bin/backup.sh script so that it does not interfere with other processes:

/usr/bin/ionice -c2 -n7 /usr/local/bin/backup.sh

The -n parameter must be between 0 and 7, where lower numbers mean higher priority.

Sponsored

To reduce the CPU priority, use the command nice:

Sponsored
/usr/bin/nice -n 19 /usr/local/bin/backup.sh

The -n parameter can range from -20 to 19, where lower numbers mean higher priority

Nice and ionice can also be combined, to run a script at low I/O and CPU priority:

/usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/local/bin/backup.sh

The post Reduce CPU and Disk load of backup scripts with nice and ionice appeared first on FAQforge.

Ubuntu Server Admin

Recent Posts

Join Canonical at HPE Discover Las Vegas 2025

Canonical, the publisher of Ubuntu and trusted open source solutions provider, is proud to sponsor HPE Discover Las…

2 hours ago

Ubuntu Weekly Newsletter Issue 896

Welcome to the Ubuntu Weekly Newsletter, Issue 896 for the week of June 8 –…

19 hours ago

Karafka 2.5 and Web UI 0.11: Next-Gen Consumer Control and Operational Excellence

Introduction Imagine pausing a problematic partition, skipping a corrupted message, and resuming processing - all…

1 day ago

How to Install and Run Mail-in-a-Box on Ubuntu VPS

This step-by-step guide will show you how to install and run Mail-in-a-Box on Ubuntu VPS.…

1 day ago

How to Deploy Keycloak on Ubuntu VPS

Here’s a clear and detailed how-to guide for how to deploy Keycloak on Ubuntu VPS.…

1 day ago

Canonical delivers Kubernetes platform and open-source security with NVIDIA Enterprise AI Factory validated design

Reference architectures speed up time to market for agentic AI projects To ease the path…

6 days ago