Running My Home NAS Backups with `nice` and `ionice` So My Desktop Never Freezes

Running a nightly backup from a home NAS to a desktop is a common task, but the copy can still hog the machine’s resources and make the UI feel sluggish.
The trick is to let the backup run with low CPU and I/O priority so the desktop stays responsive. Two simple tools—nice and ionice—are all you need.

Why the problem matters

When a rsync or tar job copies gigabytes of data, the kernel’s scheduler keeps the process in the foreground class. Even if you’re not actively using the machine, the backup can consume CPU cycles and saturate the disk queue. On a laptop or a desktop with a single NVMe drive, this shows up as a frozen terminal, delayed window redraws, or a sluggish browser.

The solution is to lower the process’s priority in both dimensions:

  • CPU priority – nice sets the niceness value, a static priority that the scheduler uses when choosing which process to run next.
  • I/O priority – ionice sets the I/O class and priority, telling the block layer to favor other processes when the disk is busy.

When both are tuned correctly, the backup runs in the background without affecting interactive workloads.

Choosing the right priority levels

Parameter Value Effect
nice +19 Lowest CPU priority; the process will only run when no higher‑priority tasks are ready.
ionice class idle I/O class idle tells the kernel to use the backup only when no other process needs the disk.
ionice class best-effort + priority 7 Slightly higher I/O priority than idle but still low; useful if you need the backup to finish faster without fully blocking other I/O.

The nice range is from -20 (highest) to +19 (lowest). ionice has three classes:

  • idle – runs only when the disk is otherwise idle.
  • best-effort – runs with a priority from 0 (highest) to 7 (lowest).
  • realtime – should be avoided for backups; it can starve other processes.

For most home setups, nice +19 + ionice -c idle is sufficient. If you notice the backup taking too long, bump the ionice priority to -c best -n 5 and keep nice +19.

Putting it together: a one‑liner

nice -n 19 ionice -c idle rsync -a --delete /mnt/nas/ /home/user/backup/
  • nice -n 19 – set the lowest CPU priority.
  • ionice -c idle – set I/O priority to idle.
  • rsync -a --delete – archive mode with delete‑to‑mirror.

If you prefer tar, the same idea applies:

nice -n 19 ionice -c idle tar -czf /home/user/backup/nas-$(date +%F).tar.gz -C /mnt/nas .

Both commands will run quietly in the background, allowing you to browse the web or edit documents without interruption.

Persisting with systemd timers

Instead of launching the backup manually, create a systemd service and timer so the job runs automatically at night.

/etc/systemd/system/nas-backup.service

[Unit]
Description=Home NAS backup

[Service]
Type=oneshot
ExecStart=/usr/bin/nice -n 19 /usr/bin/ionice -c idle /usr/bin/rsync -a --delete /mnt/nas/ /home/user/backup/

/etc/systemd/system/nas-backup.timer

[Unit]
Description=Run NAS backup nightly

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true

[Install]
WantedBy=timers.target

Enable and start:

sudo systemctl enable --now nas-backup.timer

The timer will fire at 2 AM every day, giving the backup a quiet window. If you need to tweak the schedule, edit the OnCalendar line; see the systemd timer documentation on systemd.io for more patterns.

Monitoring and troubleshooting

  • CPU usage – top or htop will show the backup process with a high nice value (e.g., +19). It should stay at 0–5 % CPU most of the time.
  • I/O queue – iostat -xz 1 (from sysstat) shows the I/O class. The backup should appear in the idle queue only when the disk is otherwise idle.
  • Disk latency – dstat -cdl or iotop can confirm that the backup isn’t raising average latency.

If the backup still interferes, double‑check that you’re not running it as root. Running as a regular user limits the process to the user’s cgroup, which is a good security practice. Also, ensure the destination directory is on a separate partition or SSD if possible; this isolates the backup I/O from the desktop’s main filesystem.

Security note

Running backups as a non‑privileged user reduces the risk of accidental data loss or privilege escalation. If you need to copy system files, consider mounting the NAS with uid/gid options that map to a dedicated backup user. Keep the backup directory’s permissions tight (chmod 700), and use rsync’s --chmod option to enforce the desired mode on the target.

Quick reference

Command What it does
nice -n 19 Lowest CPU priority
ionice -c idle I/O only when idle
ionice -c best -n 5 Lower‑than‑normal I/O priority
systemctl enable --now nas-backup.timer Schedule nightly backup

With these settings, your desktop stays snappy while your NAS data is safely mirrored. No extra software, no kernel tweaks, just a couple of shell commands and a systemd timer.


See also