Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Put a test in your shell script that checks if the drive is mounted, if not, then exit before rsync is called. Your test could be as simple as looking to see if a file exists, that would only exist if the remote filesystem is amounted test -f /remote/file .... –  Zoredache Dec 19 '12 at 19:40
add comment

2 Answers

up vote 1 down vote accepted

You can add this to your shell script before rsync runs:

if ! mount | grep -q '/media/backups'; then
    echo "/media/backups not mounted"
    exit 1
fi
share|improve this answer
    
Chris Nava's answer sounds like it would work as well, but I'm using this approach. Thanks! –  erictheavg Dec 19 '12 at 20:29
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.