How to Nice Rsync Process Priority When Using rsync+ssh for Remote Backups


1 views

When running rsync over SSH for remote backups, the process can consume significant CPU resources on the remote machine. This becomes particularly problematic during business hours when the same server hosts critical applications like version control systems (e.g., Git) or issue trackers (e.g., Bugzilla).

The most straightforward solution is to wrap the remote rsync command with nice:

rsync -avz --rsync-path="nice -n19 rsync" /local/path/ user@remote:/remote/path/

This command:

  • Uses --rsync-path to specify the remote command
  • Wraps rsync with nice -n19 (lowest priority)
  • Maintains all standard rsync functionality

For frequent use, configure your SSH client to always nice remote commands:

Host backup-server
    HostName remote.example.com
    User backup-user
    RemoteCommand nice -n19 /bin/bash
    RequestTTY force

Then use with ssh -t backup-server rsync ...

For even better resource management, combine with ionice:

rsync -avz --rsync-path="nice -n19 ionice -c3 rsync" src/ user@remote:dst/

This sets both CPU and I/O priority to lowest levels.

For scheduled backups, modify your cron job:

0 4 * * * /usr/bin/rsync -az --rsync-path="nice -n19 rsync" /backup/ user@remote:/storage/
  • Verify nice level: ps -eo pid,ni,comm | grep rsync
  • Check for permission issues with nice
  • Test with -n10 first before going to -n19

Monitor system load before/after implementation:

# Before
sar -u 60 5

# After implementing nice
sar -u 60 5

We've all been there - a scheduled backup rsync job starts running via SSH and suddenly your remote server becomes unresponsive. Checking top reveals the culprit:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
backups  16651 86.2  0.1   3576  1636 ?        Rs   11:06   0:06 rsync --server --sender -vlogDtpre.iLsfxC...

You might try:

ssh user@remote "nice -n 19 rsync [options]"

But this often fails because:

  • The remote shell might not preserve the nice value
  • rsync might spawn new processes that don't inherit the nice level
  • Some systems restrict nice values for non-root users

1. Using ionice (for Linux systems)

Combine with nice for best results:

ssh user@remote "ionice -c 3 nice -n 19 rsync --server --sender [options]"

This sets:

  • I/O class to idle (-c 3)
  • CPU priority to lowest (-n 19)

2. Wrapper Script Approach

Create a wrapper on the remote server (/usr/local/bin/lowprio_rsync):

#!/bin/bash
ionice -c 3 nice -n 19 /usr/bin/rsync "$@"

Then call it via SSH:

ssh user@remote "lowprio_rsync --server --sender [options]"

3. Systemd Service Units (For Modern Systems)

Create a service file (/etc/systemd/system/lowprio-rsync.service):

[Unit]
Description=Low Priority rsync Service

[Service]
Nice=19
IOSchedulingClass=idle
ExecStart=/usr/bin/rsync [your options here]

For your backup cron, modify to:

0 4 * * * /usr/bin/ssh -t user@remote "sudo /usr/local/bin/lowprio_rsync [options]"

After implementation, verify with:

ssh user@remote "ps -eo pid,ni,cls,cmd | grep rsync"

You should see NI=19 and CLS=3 in the output.

For even better control on Linux:

ssh user@remote "cgcreate -g cpu,blkio:/backup && \
cgset -r cpu.shares=10 backup && \
cgset -r blkio.weight=10 backup && \
cgexec -g cpu,blkio:backup nice -n 19 rsync [options]"