Rsync won’t Give Up Writing to an Unmounted Remote Drive

rsyncunmounting

I've been having issues with a external hard drive staying mounted to a mount point. That's not the topic of this question, but background info.

The issue is with rsync. It doesn't seem to recognize when it is trying to sync to an immutable destination.

You see, when this drive is not properly mounted, all that is left is it's mount-point folder, which I've made immutable.

Instead of rsync realizing that it cannot transfer to this mount-point, it proceeds transferring several gigs to this remote destination. Instead of failing, it looks at the situation as though "hey, this destination doesn't have any of the files I've been told to sync here, so I better move all files as though it was a new first time transfer".

I wish rsync would error out, but instead it tries to write 100,000 files to this mount point, failing on each file.

Best Answer

I don't know if you have the freedom to decide your destination path, but if you have that, what you can use is the following trick.

Make a directory xyz in the mount-point folder and change the permissions using chmod 000 xyz. Then mount the drive on the mount-point and make directory xyz leaving the permissions normal. Adjust the rsync have as destination /your-mount-point/xyz/ and if the drive is not mounted rsync will exit with an error:

rsync: change_dir#1 "/your-mount-point/xyz/" failed: Permission denied (13)
rsync error: errors selecting input/output files, dirs (code 3) at main.c(562) [Receiver=3.0.9]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]

If the drive is mounted, rsync will just work fine.

Related Question