Date: Sat, 21 Jun 2008 18:06:17 -0500 From: Tim Daneliuk <tundra@tundraware.com> To: Roland Smith <rsmith@xs4all.nl> Cc: Helge Rohde <heroh@gmx.de>, freebsd-questions@freebsd.org Subject: Re: shellscript conditional to check for external disk Message-ID: <485D8969.1070704@tundraware.com> In-Reply-To: <20080621224731.GA26997@slackbox.xs4all.nl> References: <200806212144.09925.heroh@gmx.de> <20080621224731.GA26997@slackbox.xs4all.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
Roland Smith wrote: > On Sat, Jun 21, 2008 at 09:44:09PM +0000, Helge Rohde wrote: >> Hello List, >> >> I need to write a backup script, and one of the required actions would be a >> copy of the backup to an external firewire drive. I would like to make this >> as easy as possible for the local staff, so i'd like to check whether the >> drive is attached, if necessary mount it, copy over the backup and unmount >> it again, so that the local staff can swap the external disks when they're >> not used. >> >> Is there a canonical way to achieve what i want? I played with the idea of >> simply checking for /dev/da0s1d's existance, but that won't disappear on >> disconnect, so that would leave the is a possibility that although da0 is >> in /dev, it might not be connected. > > Use glabel(8) to give the device an unique label. There is no telling > which device /dev/da0s1d is pointing to! After labeling you can check > for /dev/<fstype>/<yourlabel>, which should be unique. > > Make sure to unmount the drive at the end of the backup script, or > you'll get a kernel panic when staff pulls the plug on a mounted device. > > Roland A variant of this approach that is filesystem independent would be to simply write an identifying zero-length file in the root of the removable backup drive: mount /mountpoint /dev/device cd /mountpoint && touch ThisIsABackupDrive Your backup script can just look for the presence of the file "ThisIsABackupDrive" whenever it is checking to see whether the drive is mounted. Since this is done at the filename level rather than in the disk metadata, your script doesn't care/have to change if the removable drive is formatted NTFS, FAT32, ufs, etc. I use such disks myself for the exact reason you do, but I keep them FAT32 because pretty much everything can read this filesystem. Of course, FAT32 cannot preserve the file naming and permissions semantics of ufs, so I just make by backups into a tarball and then copy the tarball to the removable drive. <Shameless Plug Follows> I wrote a script to automate much of this: http://www.tundraware.com/Software/tbku/ HTH, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?485D8969.1070704>