0

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.

  • 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
1

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
  • 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
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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