Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Ubuntu 9.10, connected to external WD 1.5GB USB drive, called "data_3"

I connected the USB cord and all was well for a long time. Ran nightly cron jobs rsyncing data via the internal network.

After a powerout, after which the external USB did not start, the rsync job COPIED the data to /media/data_3, on the INTERNAL drive which is much smaller and ran out of space.

The rsync script points to the supposedly mounted USB drive at /media/data_3, but when it does not exist it writes to /media/data_3, on the internal drive.

How get rsync to write only to the USB disk, and fail if it's not mounted ?

share|improve this question

3 Answers 3

up vote 0 down vote accepted

You'll need to check beforehand if the disk is mounted (via mount and grep), and then have the script fail if it is not.

share|improve this answer

You can create a file on the external drive and test for its presence before running rsync.

if [ -e /media/data_3/testfile ]; then rsync /source/directory /media/data_3/destination; fi should work as a one line in bash at least. You can add an else condition to send you a mail if the file doesn't exist (meaning the partition isn't mounted, or isn't mounted in the right place).

share|improve this answer

Something I tried a few years ago now, was to make the mount point directory read only so that if the device wasn't present, the copy would fail. I think it also meant that I had to include the device in fstab and mount it manually if plugged in after booting.

share|improve this answer

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.