0

I am on Ubuntu 20.04 and I use the bash script / rsync below to connect to rsync-daemon on my remote server over ssh.

The downside is that using rsync over ssh also creates server load, therefore as to overcome the problem of server load, I added an ionice value as shown below. Load is no longer a problem.

My issue is that the ionice value seem to cause an unstable ssh connection and that in turn causes my login-notifier script to send a million emails because ssh keeps dropping and re-connecting continuously.

Might someone see a better solution to the load problem and/or know how to keep the ssh connection stable?

#!/bin/bash
while [ 1 ]
do
     rsync -avzxP --delete --checksum --append-verify --timeout=180 --bwlimit=48 --rsync-path="sudo ionice -c 3 rsync" --log-file=/var/log/rsync.log --exclude 'var-logs' --password-file=/etc/rsyncd.passwd -e "ssh -l backups" XXX.XX.XXX.XX::backup-data /media/username/WebMade/Server-Backups/Prod/today/
    if [ "$?" = "0" ] ; then
        echo "rsync completed normally"
        exit
    else
        echo "Rsync failure. Backing off and retrying..."
        sleep 10
    fi
done
#EOF
3
  • Side note: [ 1 ] checks if 1 is a non-empty string. [ 0 ] checks if 0 is a non-empty string. Each returns success. This means 1 you used has no connection to the logic of the script; it only looks relevant if you don't know how [ works. true (not [ true ]) makes more sense here, as false (unlike [ 0 ] or [ false ]) would really disable the loop. : is a no-op that returns success, it's the simplest what you can use here (and I don't mean [ : ], I mean sole : in place of this [ 1 ] of yours). Commented Jul 11, 2022 at 4:10
  • @KamilMaciorowski.. thanks for the feedback will give it a try.. not a coder.. stealing scripts as I go.. which sometimes doesn't work so well.. ;-) Commented Jul 11, 2022 at 4:29
  • (1) When you say "remote server", it's clear; when you later say "server", it's not clear if you mean "local" or "remote". (2) I don't see nice in the code, I see ionice. Commented Jul 11, 2022 at 8:16

1 Answer 1

1

With this rsync command you're pulling files from the remote computer to your local computer.

The -z option asks the remote computer's rsync daemon to compress the file data that it streams through the network to your local rsync (and your local rsync decompresses the data before writing it to files). The ionice specified in the --rsync-path option reduces the disk i/o priority of the rsync process on the remote computer.

A process that's reading files from disk on a computer doesn't usually add a lot of load to the computer unless the disk is slow, so the ionice is not likely to help reduce load on the remote computer. With data compression, the process that's performing the compression often adds a lot of cpu load to the computer, while the process that's decompressing the data adds very little cpu load. The --bwlimit option can be useful when the file transfer consumes all the bandwidth of the network between the two computers, but a clogged network will not usually display itself as extra load in either computer.

In my experience, asking rsync to compress the data it transfers through the network (the -z option) is not very useful when the network connection between the computers works at the high speeds in a LAN or through most modern "high speed" Internet links to homes. You gain little or no reduction in the time it takes to transfer the files, at the cost of higher cpu consumption on the sending side.

Based on this, my advice is to remove the --bwlimit and --rsync-path and -z options. The last was most likely causing the server load you've been trying to solve.

1
  • you were spot on... While I need --bwlimit b/c prod only has 4 Mbps and this eats my bandwidth.. I removed "ionice -c 3" from --rsync-path and ditched the -z option... peaceful harmonious balance has been reached in regards to server load.. thanks. Commented Jul 15, 2022 at 0:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.