![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
|
General Help All your general support questions for Ubuntu, Kubuntu, Edubuntu and Xubuntu. |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
Extra Roomy Joe
![]() Join Date: Mar 2008
Beans: 4,715
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
Okay, I just did a test and managed to successfully autobackup a directory on to an NTFS partition on a USB flash drive.
This is what I did: I made a file called Code:
/etc/udev/rules.d/81-local.rules Quote:
Code:
SUBSYSTEM=="block", SUBSYSTEMS=="usb", KERNEL=="sd?1", RUN+="/usr/local/bin/test.sh" Code:
#!/bin/sh mount /dev/sdb1 /mnt rsync -a /home/user/test/ /mnt/test/ I'm not familiar with how sbackupd works. Are you willing to try rsync? I like rsync. Also, let's start by making the script as simple as possible -- comment out the notify-send commands. Good luck with the chkdisk. Once you are done with that, it looks like it should be quite easy to setup autobackup using udev. Edit: Oh -- I'm very glad you got the drive to work again! Last edited by unutbu; March 12th, 2009 at 04:38 PM.. |
|
|
|
|
|
|
#12 |
|
Gee! These Aren't Roasted!
![]() Join Date: Feb 2009
Location: Belgium
Beans: 205
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
Hey,
I need to go now, I'll check the thread again tomorow. Thanks for all your help. If anybody else knows what the problem could be, don't hesitate |
|
|
|
|
|
#13 | |
|
Gee! These Aren't Roasted!
![]() Join Date: Feb 2009
Location: Belgium
Beans: 205
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
Hey,
Thanks for doing this for me! I moved my rules to /etc/udev/rules.d/81-local.rules Code:
SUBSYSTEMS=="usb", KERNEL=="sd?1", ATTRS{product}=="Freecom Network Drive", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"
Code:
#!/bin/sh mount /dev/sdb1 /mnt # /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." env > /mnt/env.out What happens: The drive is still being mounted on /media/FREECOM HDD (where this name comes from, I don't know). And a file is created in /mnt/env.out, but the drive isn't mounted there. EDIT: The mount failed because I gave the name "freecomHD" to the device in udev. Doing mount /dev/freecomHD fixed it. Quote:
Nothing ever seems to go according to plan in my world. Thanks! Last edited by Rackstar; March 13th, 2009 at 07:28 AM.. Reason: Bug fix |
|
|
|
|
|
|
#14 |
|
Gee! These Aren't Roasted!
![]() Join Date: Feb 2009
Location: Belgium
Beans: 205
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
Hey!
The good news is, that it now backups when I plug it in. Which was the main purpose. Now some annoying little things that show up: When I plug it in, it shows a media icon in the panel (using gnome). It then backups. And then another usb-device icon appears. The sad part is, I can't unmount the media. I'm only able to unmount it doing Code:
sudo umount /media/freecom Also the notifications don't show. Probably because the script is run by root. Doing Code:
/usr/bin/notify-send -t 0 "Backup Message" "Backup" Code:
sudo /usr/bin/notify-send -t 0 "Backup Message" "Backup" Maybe there is some parameter, I'll have a look around. Thanks! |
|
|
|
|
|
#15 |
|
Extra Roomy Joe
![]() Join Date: Mar 2008
Beans: 4,715
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
Hey, I think we are making progress!
To get notify-send working: Save this gnome-hack script to /usr/local/bin/alt-notify-send Make it executable: Code:
chmod 755 /usr/local/bin/alt-notify-send Code:
su USER alt-notify-send "Backup Message" "Backup" 0 I've tried this script and got it to work when I plugged in a USB flash drive. The reason why notify-send was not working was because notify-send uses the DBUS_SESSION_BUS_ADDRESS environment variable and that variable was not set in the shell that runs your script. This environment variable is set when you start a gnome session, but is not set when root runs a udev rule. Moreover, one user can not send messages to another user using notify-send. So we use "su" to change root to your normal user, and we use the alt-notify-send script to find and set the DBUS_SESSION_BUS_ADDRESS before launching notify-send. To fix the umount problem, please post your script. Last edited by unutbu; March 13th, 2009 at 09:02 AM.. |
|
|
|
|
|
#16 |
|
Gee! These Aren't Roasted!
![]() Join Date: Feb 2009
Location: Belgium
Beans: 205
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
I also found a variant of this script, but didn't got it working. I tried yours, but it didn't also do a thing.
This is the hack you linked to. I also tried changing whoami to my username, but then it kept saying, ruben: not found. Code:
ruben@ruben-laptop:~$ alt-notify-send "test" /usr/local/bin/alt-notify-send: 2: ruben: not found pgrep: invalid user name: gnome-session Code:
#!/bin/sh
user=`whoami`
pids=`pgrep -u $user gnome-session`
title=$1
text=$2
timeout=$3
if [ -z "$title" ]; then
echo You need to give me a title >&2
exit 1
fi
if [ -z "$text" ]; then
text=$title
fi
if [ -z "$timeout" ]; then
timeout=60000
fi
for pid in $pids; do
# find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
# use it
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
notify-send -u low -t $timeout "$title" "$text"
done
And this is my script. Code:
#!/bin/bash mount /dev/freecomHD /media/freecom/ su ruben alt-notify-send "Backup Message" "backup" 0 sleep 5 # sbackupd su ruben alt-notify-send "Backup Message" "Your USB Backup has completed." 0 Thank you very much for helping me get this far! EDIT: a little more information about the unmount bug: http://www.ninetynine.be/screens/e73...df4236e3f3.png It's in dutch, it says: "Could not unmount, the device was probably mounted manually in terminal". Rest is in english. Last edited by Rackstar; March 13th, 2009 at 09:25 AM.. |
|
|
|
|
|
#17 |
|
Extra Roomy Joe
![]() Join Date: Mar 2008
Beans: 4,715
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
After getting the "Could not unmount" error window, go to the terminal and type
Code:
mount Now, regarding alt-notify-send: what is the output of these two commands when run from the terminal: Code:
ps axuw | grep gnome-session pgrep gnome-session |
|
|
|
|
|
#18 |
|
Gee! These Aren't Roasted!
![]() Join Date: Feb 2009
Location: Belgium
Beans: 205
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
Not always getting error message, sometimes it just does nothing, like now.
Got two icons on my gnome panel. ------------------- | usb device icon | ------------------- options: mount FREECOM HDD -------------- | drive icon | -------------- options: Open freecom unmount freecom Except Open, all of the options don't do anything. mount output: Code:
ruben@ruben-laptop:~$ mount /dev/sda6 on / type ext3 (rw,relatime,errors=remount-ro) tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) /proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) varrun on /var/run type tmpfs (rw,nosuid,mode=0755) varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777) udev on /dev type tmpfs (rw,mode=0755) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620) fusectl on /sys/fs/fuse/connections type fusectl (rw) lrm on /lib/modules/2.6.27-11-generic/volatile type tmpfs (rw,mode=755) /dev/sda4 on /home type ext3 (rw,relatime) securityfs on /sys/kernel/security type securityfs (rw) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) gvfs-fuse-daemon on /home/ruben/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=ruben) /dev/freecomHD on /media/freecom type fuseblk (rw,nosuid,nodev,allow_other,blksize=4096) Code:
ruben@ruben-laptop:~$ ps axuw | grep gnome-session ruben 5818 0.0 0.1 14172 3748 ? S 14:33 0:00 /usr/lib/gnome-session/helpers/gnome-keyring-daemon-wrapper ruben 7249 0.0 0.0 3256 816 pts/0 S+ 14:52 0:00 grep gnome-session Code:
ruben@ruben-laptop:~$ pgrep gnome-session ruben@ruben-laptop:~$ EDIT: sorry, got to go, will be back in about 2 hours. Last edited by Rackstar; March 13th, 2009 at 09:55 AM.. |
|
|
|
|
|
#19 | |
|
Extra Roomy Joe
![]() Join Date: Mar 2008
Beans: 4,715
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
Quote:
Since you are running a gnome-panel, let's try this: Edit /usr/bin/local/alt-notify-send by changing Code:
pids=`pgrep -u $user gnome-session` Code:
pids=`pgrep -u $user gnome-panel` Code:
pstree Code:
umount /dev/freecomHD |
|
|
|
|
|
|
#20 |
|
Gee! These Aren't Roasted!
![]() Join Date: Feb 2009
Location: Belgium
Beans: 205
Ubuntu 9.10 Karmic Koala
|
Re: Running backup script with udev
Haha!
I could kiss you! Everything works! It has a very handy side-effect. When plugging in the drive icon appears on my gnome-panel, and I still can't unmount it using the button "Unmount", but probably only in terminal. But because of adding "umount /dev/freecomHD" to the script, the drive icon disappears, and the usb-device icon appears, which I can unmount. So basically, I can't unmount it while doing the backup, which is good Yesssss, backupping never has been so much fun. For reference: /etc/udev/rules.d/81-local.rules: Code:
SUBSYSTEMS=="usb", KERNEL=="sd?1", ATTRS{product}=="Freecom Network Drive", NAME="freecomHD", RUN+="/usr/bin/usb_backup.sh"
Code:
#!/bin/bash mount /dev/freecomHD /media/freecom/ su ruben alt-notify-send "Backup Message" "USB Backup device detected" 0 sleep 5 sbackupd su ruben alt-notify-send "Backup Message" "Your USB Backup is completed." 0 umount /dev/freecomHD Code:
#!/bin/sh
user=`whoami`
pids=`pgrep -u $user gnome-panel`
title=$1
text=$2
timeout=$3
if [ -z "$title" ]; then
echo You need to give me a title >&2
exit 1
fi
if [ -z "$text" ]; then
text=$title
fi
if [ -z "$timeout" ]; then
timeout=60000
fi
for pid in $pids; do
# find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
# use it
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
notify-send -u low -t $timeout "$title" "$text"
done
This makes this thread solved, I guess. |
|
|
|
| Bookmarks |
| Tags |
| backup, sbackup, udev, usb, usb drive |
| Thread Tools | |
| Display Modes | |
|
|