I have a shell script on my Ubuntu 10.04 Server that runs every night and uses rsync to backup files to an external share mounted to the /media/backups folder.
The problem is, sometimes the drive isn't mounted, or the destination server is offline. When this happens, my server will happily save to a folder called /media/backups on the local filesystem, quickly filling up all available disk space.
How do you prevent rsync from writing to a folder unless that folder is a mountpoint? I just can't seem to find an answer to this on my own.
With the drive unmounted, create a folder in that location and set it's permissions to 000, then mount the device over the existing folder.
You can add this to your shell script before rsync runs: