When power is cut to a typical hard disc, one of two things happens. First, the head will just sit there between the platters, and if you shake the drive or drop it (or whatever), then the disc will get scratched and you will lose data. Second, (preferably) the head will perform an emergency retraction and get itself out from between the platters. This is a good thing because it means that it won't stay in there and delete your precious bits, but it's still not ideal because there is the potential for it to scratch your disc on the way home. So, ideally, the disc should be stopped before the power is removed.
But, in this case, I'm not running OSX or Windows - I'm running Linux, and Linux doesn't have a simple, built-in, all-in-one solution for this.
The first program I tried was scsiadd. Random Bits has a pretty good post on scsiadd, and I was hopeful, but I found that, for whatever reason, it didn't work for me.
sdparm is what I was looking for, and it works like a charm.
As a side note, I probably should also suspend the USB port as Yan Li suggests, but my kernel doesn't like that so I didn't bother.
The script that I've settled on (for now) is:
#!/bin/sh
mount /dev/sdb /media/backup
rsync -vaxE --delete --ignore-errors / /media/backup/
umount /dev/sdb
## spin the disc down
sdparm -C stop /dev/sdb
## wait for disc to spin down
sleep 10
echo "Done"
I'll probably add a few more lines to check stuff like whether something is actually at /dev/sdb but this script already does pretty much everything I need it to.
HOT
ReplyDelete