Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 41

Thread: Running backup script with udev

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

    Re: Running backup script with udev

    Stupid question but: How do I mark this thread as solved?

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

    Re: Running backup script with udev

    Fantastic. So happy to hear the udev backup script is working to your liking

    Don't worry about marking the thread Solved; that feature has been disabled for the sake of server stability: http://ubuntuforums.org/showthread.php?t=1044714

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

    Re: Running backup script with udev

    Hey,

    I was thinking about the unmount problem, maybe there is a more elegant way.

    The idea is: enter a line into /etc/fstab about mounting the device, use udev to run the script in background using "&". and include a sleep of 10 seconds in the script, so that the drive had had enough time to mount.

    Result: drive get mounted, and backup in background, drive immediately ready to use.

    But I tried entering a line into fstab, and on pluggin in I got: "only root can mount", which was a suprise to me, because this thread suggests it:
    http://ubuntuforums.org/showthread.php?t=168221

    Is this idea an option, or a no go?
    Pretty happy how the situation is now, but still a little messy.

    Thanks in advance.

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

    Re: Running backup script with udev

    Hm. Your idea sounds interesting and reasonable... Though if we are going to wait for HAL to mount the device, then perhaps executing the script via a HAL policy rather than udev is a better idea after all

    Regarding the "only root can mount" error... Please post your /etc/fstab. At the moment I don't know the answer, but we shall figure it out, yes?

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

    Re: Running backup script with udev

    Hi!

    I really like the way you think. Unfortunally I'll be gone this weekend. I switched to rsync (because sbackup was taking way too much space). And now I'm running it, so the backup will take a lot of time.

    Is it ok, that I'll come back to it after the weekend? Just letting you know, I really appreciate your help, and not that you would think I just stopped replying.

    See you later.

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

    Re: Running backup script with udev

    Bad news:

    If the backup takes more than a couple of minutes. Then no usb-device icon appears after the backup.

    There should be another solution. But I could not find a lot about HAL on the internet.

    I will get back to you, after the weekend.

    Thanks!

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

    Re: Running backup script with udev

    Hi there, I'm back.

    This is the error I get:
    http://www.ninetynine.be/screens/348...b70714589f.png
    In english: "Only root can mount ..."

    This is my fstab.
    Code:
    /dev/freecomHD  /media/freecom/         ntfs-3g defaults 0 0
    Or if you would want to try with HAL, it's ok with me, but I really haven't got a clue how that works..

    Thanks in advance!

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

    Re: Running backup script with udev

    Hi Rackstar,
    It is fortunate that you went away for the weekend -- it gave me some time to research this problem. My idea to use HAL policy files seems to be a mistake. After much searching, it seems there is no way to tell HAL to run a script when a USB drive is plugged in. There is a way to do it with dbus (I have a working script!) but it is no easier than using udev, so let's see if we can make udev work first.

    Let's try this:

    Edit /usr/bin/usb_backup.sh:
    Code:
    #!/bin/bash
    /usr/bin/usb_backup_main.sh &
    Next, save in /usr/bin/usb_backup_main.sh:
    Code:
    #!/bin/bash
    mount_point=$(grep freecomHD /etc/mtab)
    attempts=1
    while [ -z $mount_point ] && [ "$attempts" -le 50 ]; do
        # $mount_point has not been found
        # quit if this fails more than 50 times. 
        # This should not be necessary, but it better to be safe
        # than have the script trapped in this loop forever for
        # some unforeseen reason.
        sleep 1
        mount_point=$(grep freecomHD /etc/mtab)
        attempts=$(($attempts+1))
    done
    
    if [ -n "$mount_point" ]; then
        su ruben alt-notify-send "Backup Message" "USB Backup device detected" 0
        sbackupd
        su ruben alt-notify-send "Backup Message" "Your USB Backup is completed." 0
    fi
    Make /usr/bin/usb_backup_main.sh executable:
    Code:
    sudo chmod 755 /usr/bin/usb_backup_main.sh

    When udev detects your USB drive, /usr/bin/usb_backup.sh is run.
    usb_backup.sh launches usb_backup_main.sh in the background, and then ends quickly. It is important that usb_backup.sh finishes quickly, since HAL does not automount the partitions until usb_backup.sh ends.

    Meanwhile, usb_backup_main.sh is running in the background, checking to see if /dev/freecomHD has been mounted. When it detects that /dev/freecomHD has been mounted, it does the backup.

    I've run a modified version of this setup on my machine and managed to get it to work.
    Last edited by unutbu; March 17th, 2009 at 02:03 AM. Reason: Removed a dangling apostrophe from code

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

    Re: Running backup script with udev

    Wow, thank you for doing all this effort!

    I believe you have a little syntax error in your code:
    Code:
    mount_point=$(grep freecomHD /etc/mtab')
    shouldn't it be:

    Code:
    mount_point=$(grep freecomHD '/etc/mtab')
    ?

    (Otherwise I get an error of missing ")")

    But I still get error:
    Code:
    ruben@ruben-laptop:~$ sudo usb_backup_main.sh 
    /usr/bin/usb_backup_main.sh: line 4: [: te veel argumenten
    Which means: "Too much arguments"

    This is my code:
    Code:
    #!/bin/bash
    mount_point=$(grep freecomHD /etc/mtab)
    attempts=1
    while [ -z $mount_point ] && [ "$attempts" -le 50 ]; do
        # $mount_point has not been found
        # quit if this fails more than 50 times.
        # This should not be necessary, but it better to be safe
        # than have the script trapped in this loop forever for
        # some unforeseen reason.
        sleep 1
        mount_point=$(grep freecomHD '/etc/mtab')
        attempts=$(($attempts+1))
    done
    
    if [ -n "$mount_point" ]; then
            su ruben alt-notify-send "Backup Message" "USB Backup device detected" 0
            # backup little files
    
            # rsync -a --delete --exclude-from="/home/ruben/backup_exclude.txt"  /h$
    
            # sync documents
            # rsync -a --delete /home/ruben/Documenten/ /media/freecom/Documenten/
    
            # rsync music
            # rsync -a --delete /home/ruben/Muziek/ /media/freecom/Muziek/
    
            # rsync photos
            # rsync -a  /home/ruben/Afbeeldingen/ /media/freecom/Foto\'s/
            # rsync -a  /media/freecom/Foto\'s/ /home/ruben/Afbeeldingen
    
            su ruben alt-notify-send "Backup Message" "Your USB Backup has complete$
    fi
    But it does seem to execute the code... I'll get back to you shortly

    EDIT: note that I'm using rsync now And that I did not set the paths right yet. In the next post I tried with the right paths.
    Last edited by Rackstar; March 16th, 2009 at 11:02 PM.

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

    Re: Running backup script with udev

    Hehe,

    It does the trick!

    But it still says this if I try to do the command manually:
    Code:
    ruben@ruben-laptop:~$ sudo usb_backup_main.sh 
    /usr/bin/usb_backup_main.sh: line 4: [: te veel argumenten
    Again, this means "Too much arguments"

    This is the if condition. I remember having this error a lot in college with the test command (or with the brackets [])

    But this seems to be a hell of an improvement. No ugly fixes no more, no troubles, only the one error, of which I'm a little afraid that it might cause not to do those different attempts...

    Thanks! Really really thanks, this is better help than I could ever imagine.

Page 3 of 5 FirstFirst 12345 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
  •