Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
This is good little trick. So, if the drive isn't mounted, rsync will error out for the whole transfer at once instead of trying ever single file? – Lonniebiz Mar 11 '14 at 19:47
Yes, as I understand it the receiving end closes the connection, so probably data is sent until the message comes that the other side has backed off. – Anthon Mar 11 '14 at 20:27

How is rsync supposed to know the drive's not mounted? Mount points are just folders like any other so rsync is doing exactly what you told it to, there is no error because you gave it a directory that it can see so it attempts to write to it.

A workaround would be to first make sure your drive is mounted and then run rsync. For this example, I am using the label of my external hard drive (Iomega_HDD) change accordingly:

mount | grep -q Iomega_HDD && rsync ...

The command above will run your rsync command only if the drive is mounted.

share|improve this answer
The script was attempting to mount beforehand, but I didn't have the OR-logic you're suggesting. This is a good suggestion. Thanks – Lonniebiz Mar 11 '14 at 19:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.