Re: shellscript conditional to check for external disk

2008-06-23 Thread Helge Rohde
On Monday 23 June 2008 18:24:59 Roland Smith wrote:
> On Mon, Jun 23, 2008 at 05:25:58PM +, Helge Rohde wrote:
> > On Saturday 21 June 2008 22:47:31 Roland Smith wrote:
> > > On Sat, Jun 21, 2008 at 09:44:09PM +, Helge Rohde wrote:

> > > > 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
>
> Such devices should disappear on disconnect.
That's what i thought, but since i wasnt entirely sure i let the otherwise 
perfectly working behavior convince me otherwise. Sorry for any confusion 
caused.
It seems that with the given Hardware combination fwohci runs into a bunch of 
errors and only creates the device nodes at the first time the drive is 
connected, but fails to destroy them upon disconnection. Reconnecting, mounting 
and writing to and from the device node produced no errors. 
If i connect the  drive via usb cable instead of the fw one, all goes as 
expected and umass creates and destroys the device nodes. I will investigate 
and start a new thread on it later, for now my workaround is a strip of Gaffa 
Tape over the Firewire port and the instruction to only use USB ;)

> > > > 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//, which should be unique.
>
> Let me rephrase that. You should actually use the file system's utility
> to set a label. This works for UFS (newfs, tunefs), msdosfs (newfs_msdos),
> ISO9660 (mkisofs) and ntfs.
>
> > > 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
> >
> > Okay, it obviosly makes sense to use glabel instead of the device node.
> > Will the glabel appear/disappear depending on whether the drive is
> > connected?
>
> Yes, just like regular device nodes.

I just didnt suspect just how irregular my device nodes are ;)

> > Is it possible to have more then one physical drive with the same
> > glabel(As i plan to utilize two identical Firewire disks) ?
>
> You can label both drives the same. I don't know what will happen it you
> try to connect them both at the same time. I guess that the creation of
> the second label will fail.
>
> > Either way, i still need a way to check whether a drive is attached or
> > not.
>
> Simple. Check for the device node.
>
> > Mounting( and unmounting!) will be done from the periodic backup
> > scripts.
> >
> > I am not sure how devd could help me with that, besides maybe
> > write/delete a zero-byte file somewhere and have the periodic script
> > check for its existence.
>
> It can't completely. It should be able to detect your labeled device and
> mount it somewhere. But you _have_ to unmount _before_ the device node
> disappears, lest you get the aforementioned panic.

Thats precisely why i didnt want to let devd do the mounting: doing it 
just-in-time minimises the window of opportunity for vicious plug-pullers.

> It's easier to have the backup script test if the labeled device node
> exists.
>
> Do not forget to print a message (after the script has unmounted the
> drive) for the operators that the backup is finished and that the device
> may be disconnected.

The Machine will run headless - I thought about sending a mail but i probably 
won't bother as by the time the backup and copy takes longer than a night, I 
should have received angry emails and snmp traps about filesystems way beyond 
their official capacity anyway ;)

regards,
Helge

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: shellscript conditional to check for external disk

2008-06-23 Thread Roland Smith
On Mon, Jun 23, 2008 at 05:25:58PM +, Helge Rohde wrote:
> On Saturday 21 June 2008 22:47:31 Roland Smith wrote:
> > On Sat, Jun 21, 2008 at 09:44:09PM +, 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

Such devices should disappear on disconnect.

> > > 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//, which should be unique.

Let me rephrase that. You should actually use the file system's utility
to set a label. This works for UFS (newfs, tunefs), msdosfs (newfs_msdos),
ISO9660 (mkisofs) and ntfs.

> > 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
> 
> Okay, it obviosly makes sense to use glabel instead of the device node. Will 
> the glabel appear/disappear depending on whether the drive is connected?

Yes, just like regular device nodes.

> Is it possible to have more then one physical drive with the same glabel(As i 
> plan to utilize two identical Firewire disks) ?

You can label both drives the same. I don't know what will happen it you
try to connect them both at the same time. I guess that the creation of
the second label will fail.

> Either way, i still need a way to check whether a drive is attached or not. 

Simple. Check for the device node.

> Mounting( and unmounting!) will be done from the periodic backup
> scripts.
>
> I am not sure how devd could help me with that, besides maybe write/delete a 
> zero-byte file somewhere and have the periodic script check for its 
> existence. 

It can't completely. It should be able to detect your labeled device and
mount it somewhere. But you _have_ to unmount _before_ the device node
disappears, lest you get the aforementioned panic.

It's easier to have the backup script test if the labeled device node
exists.

Do not forget to print a message (after the script has unmounted the
drive) for the operators that the backup is finished and that the device
may be disconnected.
 
> Thank you all for your help,

You're welcome!

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgpErwAj4m0h2.pgp
Description: PGP signature


Re: shellscript conditional to check for external disk

2008-06-23 Thread Helge Rohde
On Saturday 21 June 2008 22:47:31 Roland Smith wrote:
> On Sat, Jun 21, 2008 at 09:44:09PM +, 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//, 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

Okay, it obviosly makes sense to use glabel instead of the device node. Will 
the glabel appear/disappear depending on whether the drive is connected?

Is it possible to have more then one physical drive with the same glabel(As i 
plan to utilize two identical Firewire disks) ?

Either way, i still need a way to check whether a drive is attached or not. 
Mounting( and unmounting!) will be done from the periodic backup scripts.
I am not sure how devd could help me with that, besides maybe write/delete a 
zero-byte file somewhere and have the periodic script check for its 
existence. 

Thank you all for your help,
Helge
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: shellscript conditional to check for external disk

2008-06-22 Thread Wojciech Puchar


Jun 22 11:44:49 Christi kernel: umass0:  on uhub4
Jun 22 11:44:49 Christi root: Unknown USB device: vendor 0x0781 product 0x5150 b
us uhub4
Jun 22 11:44:49 Christi kernel: da0 at umass-sim0 bus 0 target 0 lun 0
Jun 22 11:44:49 Christi kernel: da0:  Removable Direct
Access SCSI-2 device
Jun 22 11:44:49 Christi kernel: da0: 40.000MB/s transfers
Jun 22 11:44:49 Christi kernel: da0: 122MB (250879 512 byte sectors: 64H 32S/T 1
22C)
Jun 22 11:44:49 Christi kernel: GEOM_LABEL: Label for provider da0s1 is msdosfs/
.
Jun 22 11:44:56 Christi kernel: umass0: at uhub4 port 2 (addr 2) disconnected
Jun 22 11:44:56 Christi kernel: (da0:umass-sim0:0:0:0): lost device
Jun 22 11:44:56 Christi kernel: (da0:umass-sim0:0:0:0): removing device entry
Jun 22 11:44:56 Christi kernel: GEOM_LABEL: Label msdosfs/  removed.
Jun 22 11:44:56 Christi kernel: umass0: detached


man devd
man devd.conf
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: shellscript conditional to check for external disk

2008-06-22 Thread Camilo Reyes
You can use /var/log/messages to check for the existence of an external
drive through a series of grep commands. Here is my log output when I
insert/remove a USB drive:

Jun 22 11:44:49 Christi kernel: umass0:  on uhub4
Jun 22 11:44:49 Christi root: Unknown USB device: vendor 0x0781 product 0x5150 b
us uhub4
Jun 22 11:44:49 Christi kernel: da0 at umass-sim0 bus 0 target 0 lun 0
Jun 22 11:44:49 Christi kernel: da0:  Removable Direct
Access SCSI-2 device
Jun 22 11:44:49 Christi kernel: da0: 40.000MB/s transfers
Jun 22 11:44:49 Christi kernel: da0: 122MB (250879 512 byte sectors: 64H 32S/T 1
22C)
Jun 22 11:44:49 Christi kernel: GEOM_LABEL: Label for provider da0s1 is msdosfs/
 .
Jun 22 11:44:56 Christi kernel: umass0: at uhub4 port 2 (addr 2) disconnected
Jun 22 11:44:56 Christi kernel: (da0:umass-sim0:0:0:0): lost device
Jun 22 11:44:56 Christi kernel: (da0:umass-sim0:0:0:0): removing device entry
Jun 22 11:44:56 Christi kernel: GEOM_LABEL: Label msdosfs/  removed.
Jun 22 11:44:56 Christi kernel: umass0: detached

I'm sure you can come up with creative ways to write a script that
checks for when the disk is detached.

"Bono Vince Malum"
--
-Camilo


> Date: Sat, 21 Jun 2008 21:44:09 +
> From: Helge Rohde <[EMAIL PROTECTED]>
> Subject: shellscript conditional to check for external disk
> To: freebsd-questions@freebsd.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain;  charset="us-ascii"
> 
> 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.
> 
> Any ideas or RTFM-pointers?
> 
> Helge


  
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: shellscript conditional to check for external disk

2008-06-22 Thread RW
On Sun, 22 Jun 2008 11:13:15 +0200
Roland Smith <[EMAIL PROTECTED]> wrote:

> On Sun, Jun 22, 2008 at 12:22:07AM +0100, RW wrote:
> > On Sun, 22 Jun 2008 00:47:31 +0200
> > Roland Smith <[EMAIL PROTECTED]> wrote:
> > 
> > 
> > > 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//, which should be
> > > unique.
> > 
> > I think that should be:
> > 
> > /dev/label/
> 
> That is only for non-filesystem labels, according to glabel(8):
> 
> "This class also provides volume label detection for file
> systems.  Those labels cannot be set with glabel, but must be set
> with the appropriate file system utility, 
> ...
>  Non file-system labels are created in the directory /dev/label/."

but you did write: "Use glabel(8) to give the device an unique
label", so it would be a non-filesystem label.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: shellscript conditional to check for external disk

2008-06-22 Thread Roland Smith
On Sat, Jun 21, 2008 at 06:06:17PM -0500, Tim Daneliuk wrote:
> > 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//, 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.

The problem is that there can be several device nodes for USB disks,
each with up to four slices times six usable partitions. How
are you going to pick the right one? You'd have to try them all.
 
> 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.

Glabel(8) supports UFS, FAT12, FAT16, FAT32, ISO9660, ext2fs, reiserfs
and ntfs.

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgp6POFCcROJH.pgp
Description: PGP signature


Re: shellscript conditional to check for external disk

2008-06-22 Thread Roland Smith
On Sun, Jun 22, 2008 at 12:22:07AM +0100, RW wrote:
> On Sun, 22 Jun 2008 00:47:31 +0200
> Roland Smith <[EMAIL PROTECTED]> wrote:
> 
> 
> > 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//, which should be unique.
> 
> I think that should be:
> 
> /dev/label/

That is only for non-filesystem labels, according to glabel(8):

"This class also provides volume label detection for file systems.  Those
 labels cannot be set with glabel, but must be set with the appropriate
 file system utility, e.g. for UFS the file system label is set with
 tunefs(8).  Currently supported file systems are:

   o   UFS1 (directory /dev/ufs/).
   o   UFS2 (directory /dev/ufs/).
   o   MSDOSFS (FAT12, FAT16, FAT32) (directory /dev/msdosfs/).
   o   CD ISO9660 (directory /dev/iso9660/).
   o   EXT2FS (directory /dev/ext2fs/).
   o   REISERFS (directory /dev/reiserfs/).
   o   NTFS (directory /dev/ntfs/).

 Non file-system labels are created in the directory /dev/label/."

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgpbyQ4XO1cnF.pgp
Description: PGP signature


Re: shellscript conditional to check for external disk

2008-06-21 Thread Wojciech Puchar

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,


won't disappear on disconnect? strange.


you may add something to devd.conf - so your script will be started on 
attach.




___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: shellscript conditional to check for external disk

2008-06-21 Thread RW
On Sun, 22 Jun 2008 00:47:31 +0200
Roland Smith <[EMAIL PROTECTED]> wrote:


> 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//, which should be unique.

I think that should be:


/dev/label/
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: shellscript conditional to check for external disk

2008-06-21 Thread Tim Daneliuk
Roland Smith wrote:
> On Sat, Jun 21, 2008 at 09:44:09PM +, 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//, 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.




I wrote a script to automate much of this:

   http://www.tundraware.com/Software/tbku/

HTH,
-- 

Tim Daneliuk [EMAIL PROTECTED]
PGP Key: http://www.tundraware.com/PGP/

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: shellscript conditional to check for external disk

2008-06-21 Thread Roland Smith
On Sat, Jun 21, 2008 at 09:44:09PM +, 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//, 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
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgpfZ1lXYyqLS.pgp
Description: PGP signature


Re: shellscript conditional to check for external disk

2008-06-21 Thread Chuck Robey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

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.
> 
> Any ideas or RTFM-pointers?

I'm not certain this will do what you want with enough security, but if you put
the commands in to mount the dist into /etc/fstab, then later on your ask simply
"mount ", mount will follow those rules to mount the disk, if it's
indeed in existence.  Putting that into a script is pretty simple.  There are a
huge number of backup commands ... I rather like tar, which can be made to
automatically compress the output, or to ask for a single file out of the whole
archive, on restoral.  Either way, not hard to automate.

Does this fit what you wanted?  There's a good man page on fstab, and y9ou
shouold read the pages on mount and tar.

> 
> Helge
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.4 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIXX3az62J6PPcoOkRArsiAJ0f/b3bQbChB9t48EUu5HhznTaetwCfc5OJ
VGflPb3nUXht709CGpaUPUQ=
=/zdL
-END PGP SIGNATURE-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"