LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Automate backup when a particular thumb drive is plugged in (https://www.linuxquestions.org/questions/slackware-14/automate-backup-when-a-particular-thumb-drive-is-plugged-in-669151/)

duryodhan 09-11-2008 05:03 AM

Automate backup when a particular thumb drive is plugged in
 
Hi

I am mobile a lot (mobile == I use a number of different computers at different places) . I also use my pen drive to store/update my files/document as I find its much easier on me (I don't live in a country where net access is easy / painless).

What I want to achieve is :

* As soon as I plug in my pen drive to my home computer running slackware (the particular drive could be recognized by its uuid) , a particular folder is automatically copied by Slackware to my ~.

Any ideas on how I could do this ?

I think HAL/udev should be able to recognize the drive, and then I need to somehow call a script.

Any cool scripts/help would be great.

thanks
duryodhan

Matir 09-11-2008 06:56 AM

Yep, udev can run a script based on criteria you specify. See: http://www.reactivated.net/writing_u...l#external-run

duryodhan 09-12-2008 12:46 PM

ok .. am not at my Slack machine right now so can't test this but quick question

wouldn't this run before HAL has mounted the USB Key... and if I haven't mounted the key how can I copy something from it ?

Matir 09-12-2008 08:45 PM

You could probably fork and return and then wait for some time and try the copy, as a thought.

T3slider 09-12-2008 09:17 PM

You could try ivman/pmount to perform commands upon plugging in the thumb drive. I have no experience with either, but I *think* it should work. pmount just allows normal users to mount via HAL (ie a console version of the WM/DE-specific events), while ivman allows you to run commands when something is plugged in. I'm not sure if you can get away with JUST using ivman or if you need pmount as well -- not having any experience is not helping me here. However, a little research should help you figure that out. rworkman *seems* to know a bit about this based on past posts, but he may never see this. You might be able to search the forums for ivman for more help.

Good luck.

duryodhan 09-13-2008 04:03 AM

Thanks for your help all.


Quote:

You could probably fork and return and then wait for some time and try the copy, as a thought.
No offense Matir , but ewww Ughhh. ... :P


T3Slider - awesome .. it worked !

I am just posting what I did here ... someone else on searching can use it (as well as you guys can comment)

to start at console -
Quote:

lshal -m
Start monitoring devicelist:
-------------------------------------------------

and plug in your usb key.

you might get something like below
Quote:

-------------------------------------------------
14:33:14.801: usb_device_90c_1000_AA04012700007909 added
14:33:14.817: usb_device_90c_1000_AA04012700007909_usbraw added
14:33:14.850: usb_device_90c_1000_AA04012700007909_if0 added
14:33:19.827: usb_device_90c_1000_AA04012700007909_if0_scsi_host added
14:33:19.829: usb_device_90c_1000_AA04012700007909_if0_scsi_host_scsi_device_lun0 added
14:33:19.832: usb_device_90c_1000_AA04012700007909_if0_scsi_host_scsi_device_lun0_scsi_generic added
14:33:19.865: storage_serial_USB_FLASH_DISK_AA04012700007909_0_0 added
14:33:19.882: volume_uuid_D8C6_02E6 added
The key thing is volume_uuid_D8C6_02E6 .. we will use it later on (the value after uuid will be different for you)

Now go to slackbuilds.org and get the builds for ivman and pmount and install both.

Now

Quote:

vim ~/.ivman/IvmConfigActions.xml
And add lines like
Quote:

<ivm:Match name="hal.volume.uuid" value="D8C6-02E6">
<ivm:Option name="mount" value="true" />
<ivm:Option name="exec" value="cp $hal.volume.mount_point$/backup/* /targetbackuppath/ -u " />
<ivm:Option name="exec" value="pumount $hal.block.device$" />
</ivm:Match>

Note that the line <ivm:Option name="mount" value="true" > is also there at the top of the same file .. I commented that one out as I didn't want ivman to automount every USB drive thats plugged in. If you don't remove it there then don't add it here.

Also note how we matched the uuid noted down earlier .
I also automatically umount after the backup is done .. I am just more comfortable with some setup like this.


Now just add ivman to your startup .. for fluxbox (like me) , I added to the ~/.fluxbox/startup file. I didn't add it to rc.local cos I don't think above will work well if I run ivman as root.

Matir 09-13-2008 10:19 AM

Much nicer solution, I must say. I'd never heard of ivman until this.

T3slider 09-13-2008 11:13 AM

Quote:

Originally Posted by duryodhan
Now just add ivman to your startup .. for fluxbox (like me) , I added to the ~/.fluxbox/startup file. I didn't add it to rc.local cos I don't think above will work well if I run ivman as root.

If you want it to work in the terminal while logged in as a regular user (and I believe it should work when in X as well), you could add ivman to ~/.bash_profile (make sure to source .bash_profile or log out and back in for the changes to take effect). .bash_profile is only executed at a login shell, ie when you first log in as your user. .bashrc is executed at every interactive (non-login) shell, so ivman would be run multiple times (obviously not a good thing), so keep it in .bash_profile if you decide to do this. If you use another shell, obviously your solution may vary. I don't use runlevel 4, but that may be more problematic (or maybe not) since you log in graphically instead. Or you could just keep it in your fluxbox startup script.


All times are GMT -5. The time now is 06:50 PM.