Create a statically-linked rsync binary

If you have a hosting contract, you may have SSH access to the server containing your files (or at least to a chrooted part of it). If so – you’re lucky! You may not feel lucky, because rsync doesn’t work because it isn’t installed by your hosting provider, but probably can just put a rsync binary there and still use rsync. It just has to contain all its dependencies in itself, which is called statically linked.

Firstly, where do you build it? On your own computer? You can do that, but it’s safer to just spin up an Alpine container and do it there:

docker run -it alpine /bin/sh

Now you’re inside the container and firstly should set some environment variables:

export CC=clang
export LDFLAGS="-static"
export PKG_CONFIG="pkg-config --static"

And also install some packages you will need:

apk add acl-dev acl-static attr-dev zstd-dev zstd-static openssl-libs-static openssl-dev make clang git

OK, you’re set. Now fetch, compile and install some dependencies of rsync which are not available via packages:

git clone https://github.com/Cyan4973/xxHash.git
cd xxHash
make
make install
cd ..
git clone https://github.com/lz4/lz4.git
cd lz4
make
make install
cd ..

And finally, do the same with rsync itself (you may want to check if there’s a more recent version):

wget https://rsync.samba.org/ftp/rsync/src/rsync-3.4.1.tar.gz
tar xvzf rsync-3.4.1.tar.gz
cd rsync-3.4.1
./configure --enable-ipv6
make

Now you should have a relatively big rsync binary – hooray! But it’s inside the container. You can get it out by opening a second terminal and checking which container ID you Alpine container has, e.g. with “docker ps”. Then use this ID to copy the binary:

docker cp CONTAINER_ID_HERE:/rsync-3.4.1/rsync /directory/on/your/computer/

Now you can upload it to your hosting and use it. If you can’t write to the system bin directory (which seems unlikely), you have to tell rsync where its counterpart is:

rsync --rsync-path=/where/it/is/on/your/hosting/rsync -avP mywebsitefiles/ user@hostingcompany:/website/