Page 1 of 5 123 ... LastLast
Results 1 to 10 of 41

Thread: Running backup script with udev

  1. #1
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    [SOLVED] Running backup script with udev

    Hello,

    I have been trying to get my backup script running when I plug my USB dive in.

    But it still seems that it refuses to work...

    These are my rules: (in /etc/udev/rules.d/10-local.rules)
    Code:
    SUBSYSTEM=="block", ATTRS{product}=="Freecom Network Drive", SUBSYSTEMS=="usb", KERNEL=="sd?1", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"
    with /usr/bin/usb_backup.sh
    Code:
    #!/bin/bash
    /usr/bin/notify-send -t 0 "Backup Message" "Backup device detected, starting backup."
    sleep 5
    sbackupd
    /usr/bin/notify-send -t 0 "Backup Message" "Your USB Backup has completed."
    The script runs as it should when I manually run it as root.


    This is what I get when I do "udevinfo -a -p $(udevinfo -q path -n /dev/sdb)".

    Code:
    looking at device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5/target5:0:0/5:0:0:0/block/sdb':
        KERNEL=="sdb"
        SUBSYSTEM=="block"
        DRIVER==""
        ATTR{range}=="16"
        ATTR{removable}=="0"
        ATTR{ro}=="0"
        ATTR{size}=="976773168"
        ATTR{capability}=="12"
        ATTR{stat}=="     439    30507    32116     2328        0        0        0        0        0     1604     2328"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5/target5:0:0/5:0:0:0/block':
        KERNELS=="block"
        SUBSYSTEMS==""
        DRIVERS==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5/target5:0:0/5:0:0:0':
        KERNELS=="5:0:0:0"
        SUBSYSTEMS=="scsi"
        DRIVERS=="sd"
        ATTRS{device_blocked}=="0"
        ATTRS{type}=="0"
        ATTRS{scsi_level}=="3"
        ATTRS{vendor}=="WDC WD50"
        ATTRS{model}=="00AAVS-00G9B0   "
        ATTRS{rev}=="    "
        ATTRS{state}=="running"
        ATTRS{timeout}=="30"
        ATTRS{iocounterbits}=="32"
        ATTRS{iorequest_cnt}=="0x1c5"
        ATTRS{iodone_cnt}=="0x1c5"
        ATTRS{ioerr_cnt}=="0x0"
        ATTRS{modalias}=="scsi:t-0x00"
        ATTRS{evt_media_change}=="0"
        ATTRS{queue_depth}=="1"
        ATTRS{queue_type}=="none"
        ATTRS{max_sectors}=="240"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5/target5:0:0':
        KERNELS=="target5:0:0"
        SUBSYSTEMS=="scsi"
        DRIVERS==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0/host5':
        KERNELS=="host5"
        SUBSYSTEMS=="scsi"
        DRIVERS==""
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6/5-6:1.0':
        KERNELS=="5-6:1.0"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb-storage"
        ATTRS{bInterfaceNumber}=="00"
        ATTRS{bAlternateSetting}==" 0"
        ATTRS{bNumEndpoints}=="02"
        ATTRS{bInterfaceClass}=="08"
        ATTRS{bInterfaceSubClass}=="06"
        ATTRS{bInterfaceProtocol}=="50"
        ATTRS{modalias}=="usb:v07ABpFCBFd0000dc00dsc00dp00ic08isc06ip50"
        ATTRS{interface}=="MSC Bulk-Only Transfer"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-6':
        KERNELS=="5-6"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ATTRS{configuration}=="USB Mass Storage"
        ATTRS{bNumInterfaces}==" 1"
        ATTRS{bConfigurationValue}=="1"
        ATTRS{bmAttributes}=="c0"
        ATTRS{bMaxPower}=="  2mA"
        ATTRS{urbnum}=="5170"
        ATTRS{idVendor}=="07ab"
        ATTRS{idProduct}=="fcbf"
        ATTRS{bcdDevice}=="0000"
        ATTRS{bDeviceClass}=="00"
        ATTRS{bDeviceSubClass}=="00"
        ATTRS{bDeviceProtocol}=="00"
        ATTRS{bNumConfigurations}=="1"
        ATTRS{bMaxPacketSize0}=="64"
        ATTRS{speed}=="480"
        ATTRS{busnum}=="5"
        ATTRS{devnum}=="8"
        ATTRS{version}==" 2.00"
        ATTRS{maxchild}=="0"
        ATTRS{quirks}=="0x0"
        ATTRS{authorized}=="1"
        ATTRS{manufacturer}=="0"
        ATTRS{product}=="Freecom Network Drive"
        ATTRS{serial}=="7D5000AA6350"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5':
        KERNELS=="usb5"
        SUBSYSTEMS=="usb"
        DRIVERS=="usb"
        ATTRS{authorized_default}=="1"
        ATTRS{configuration}==""
        ATTRS{bNumInterfaces}==" 1"
        ATTRS{bConfigurationValue}=="1"
        ATTRS{bmAttributes}=="e0"
        ATTRS{bMaxPower}=="  0mA"
        ATTRS{urbnum}=="147"
        ATTRS{idVendor}=="1d6b"
        ATTRS{idProduct}=="0002"
        ATTRS{bcdDevice}=="0206"
        ATTRS{bDeviceClass}=="09"
        ATTRS{bDeviceSubClass}=="00"
        ATTRS{bDeviceProtocol}=="00"
        ATTRS{bNumConfigurations}=="1"
        ATTRS{bMaxPacketSize0}=="64"
        ATTRS{speed}=="480"
        ATTRS{busnum}=="5"
        ATTRS{devnum}=="1"
        ATTRS{version}==" 2.00"
        ATTRS{maxchild}=="8"
        ATTRS{quirks}=="0x0"
        ATTRS{authorized}=="1"
        ATTRS{manufacturer}=="Linux 2.6.27-11-generic ehci_hcd"
        ATTRS{product}=="EHCI Host Controller"
        ATTRS{serial}=="0000:00:1d.7"
    
      looking at parent device '/devices/pci0000:00/0000:00:1d.7':
        KERNELS=="0000:00:1d.7"
        SUBSYSTEMS=="pci"
        DRIVERS=="ehci_hcd"
        ATTRS{vendor}=="0x8086"
        ATTRS{device}=="0x27cc"
        ATTRS{subsystem_vendor}=="0x1025"
        ATTRS{subsystem_device}=="0x0107"
        ATTRS{class}=="0x0c0320"
        ATTRS{irq}=="23"
        ATTRS{local_cpus}=="ffffffff,ffffffff"
        ATTRS{local_cpulist}=="0-63"
        ATTRS{modalias}=="pci:v00008086d000027CCsv00001025sd00000107bc0Csc03i20"
        ATTRS{broken_parity_status}=="0"
        ATTRS{msi_bus}==""
    
      looking at parent device '/devices/pci0000:00':
        KERNELS=="pci0000:00"
        SUBSYSTEMS==""
        DRIVERS==""
    Can anybody see the problem?
    Last edited by Rackstar; March 13th, 2009 at 07:53 PM.

  2. #2
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Running backup script with udev

    I think the udev rule should specify SUBSYSTEMS only once. So perhaps try changing

    Code:
    SUBSYSTEM=="block", ATTRS{product}=="Freecom Network Drive", SUBSYSTEMS=="usb", KERNEL=="sd?1", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"
    to
    Code:
    ATTRS{product}=="Freecom Network Drive", SUBSYSTEMS=="usb", KERNEL=="sd?1", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"

  3. #3
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev

    Hey,

    Thanks for the fast reply!

    But still nothing happens. (Also one was SUBSYSTEM, other was SUBSYSTEMS)

    EDIT: the rules this time
    Code:
    SUBSYSTEMS=="usb", KERNEL=="sd?1", ATTRS{product}=="Freecom Network Drive", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"
    Thanks. Any other idea?

  4. #4
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Running backup script with udev

    Oops, indeed you are right -- SUBSYSTEM and SUBSYSTEMS are different.
    • Did you run
      Code:
      sudo udevadm control --reload-rules
      after changing the udev rule?
    • It would be nice to know if (A) the script is being run, but quitting early, or (B) the script in never getting run at all.

      If we are in case (A), then we can stop fiddling with the udev rule and concentrate on the script.

      If (B), then we need to work on the udev rule.

      To find out if we are in case (A) or (B), perhaps try this: Edit your script by adding these two lines:
      Code:
      #!/bin/bash
      env > /tmp/env.out
      DISPLAY=:0.0
      /usr/bin/notify-send -t 0 "Backup Message" "Backup device detected, starting backup."
      sleep 5
      sbackupd
      /usr/bin/notify-send -t 0 "Backup Message" "Your USB Backup has completed."
      Run
      Code:
      sudo udevadm control --reload-rules
      Unplug and then plug in the drive. See if you get a file called /tmp/env.out.

      If you see /tmp/env.out, then we are in case (A).

      If you do not see /tmp/env.out, then we are in case (B).

  5. #5
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev

    Thank you very much for helping me out with this one!

    I used
    Code:
    sudo /etc/init.d/udev restart
    to restart it.

    I tried yours but It said:
    Code:
    ruben@ruben-laptop:~$ sudo udevadm control --reload-rules
    unrecognized command 'reload-rules'
    Some package missing?

  6. #6
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev

    For some reason, he does not want to mount the drive anymore? (Gives error dialog box)

    The env.out file is there! But no backup

    Thanks!

    See files:
    http://www.ninetynine.be/screens/76c...f8026bd192.png
    http://www.ninetynine.be/screens/c81...1a48d770ec.png

    Extra details:
    http://www.ninetynine.be/screens/7f9...92a7372bbe.png

    (please note that I was able to normally use the HDD in the past. The HDD is formatted into NTFS)
    Last edited by Rackstar; March 12th, 2009 at 08:37 PM. Reason: New files

  7. #7
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Running backup script with udev

    Did you unmount the drive before unplugging it?
    If you think this is the problem, follow taurus's advice here:
    http://ubuntuforums.org/showthread.php?t=1008357

    The more I think about this, the more I suspect udev is not the right tool for this job.

    The problem is udev is very low-level. It creates the device file for the device. HAL is a little higher level. It does its work after udev is finished. HAL automounts the USB drive. sbackupd will not work until after the USB drive is mounted. So we probably need to work on setting up a HAL policy, rather than a udev rule.

    Please note that I am not an expert at udev or HAL, so what I said above is largely speculation.

    If you agree with the above speculation, I can try to help you write a HAL policy, but it would be new ground for me too, so it may take some time unless a more knowledgable forum reader jumps in.
    Last edited by unutbu; March 12th, 2009 at 08:56 PM.

  8. #8
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev

    Hey,

    I have read something about HAL, but didn't understand it. Also I was suggested udev on this thread: http://ubuntuforums.org/showthread.p...t=backup+mount .

    I am willing to learn to use HAL. But on one of the screenshots you can see that they suggested to run chkdsk on the HDD on windows. A very strange question to me, but then again, it's in NTFS, so I can understand it.

    I'm running that chkdsk first on Windows. But it hangs on about 15% but I know there is one huge file on the disk, so I hope it's just hanging on that file. It seems unsafe to cancel this process. I choose NTFS because I need to access it on Windows too. I know ext3 should have been a better choice.

    Thanks for all the trouble! I'm pleasantly suprised of the good help on this forum.

    I'll get back to this thread from the moment the chkdsk is finished.

    Thanks

  9. #9
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev

    Quote Originally Posted by unutbu View Post
    Did you unmount the drive before unplugging it?
    If you think this is the problem, follow taurus's advice here:
    http://ubuntuforums.org/showthread.php?t=1008357
    I unplugged it a couple of hundred times today, so I can't garantee you that I unmounted it first every time

  10. #10
    Join Date
    Feb 2009
    Location
    Belgium
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Running backup script with udev

    I used chkdsk on windows, plugged it in, and it asked for a password. I just entered my root password and I could access it. There was recycle bin and a "System volume information" folder created, when I deleted it. It didn't ask a password anymore on plug in.

    env.out is still being created. But no messages pop up and no backup is performed.

    EDIT: maybe let's try HAL

    Thanks!

Page 1 of 5 123 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •