View Full Version : Backup Script
Ultra Magnus
March 20th, 2008, 08:51 PM
Hi I've been trying to write a simple backup script. I want to be able to automatically backup whenever my external hard drive is plugged in, but I don't know where to start, is there a way to execute something when a drive with a certain label is plugged in ?
Thanks
Jim
Fbot1
March 20th, 2008, 09:09 PM
is there a way to execute something when a drive with a certain label is plugged in ?
A label?
ruy_lopez
March 20th, 2008, 09:13 PM
A label?
I think he means a volume label.
Fbot1
March 20th, 2008, 09:28 PM
I think he means a volume label.
Oh, lol.
Ultra Magnus
March 25th, 2008, 09:47 PM
Hi, I know you can label a drive and mount a drive by its label, as in
mount LABEL=drivelabel /your/directory
But I was wondering whether its possible to write a script that mounts the drive automatically when the drive is plugged in and executes something like rsync to backup your stuff, so something like:
-plug in drive
-drive label is detected and mounted
-rsync backs up files
Is it even a good idea to have something running the whole time in order to poll for this or is there a good way to have something that is already running trigger the script to run?
Thanks,
Jim
mssever
March 26th, 2008, 07:23 AM
Look into udev. I believe that you can hook into udev and specify a script to run based on a number of parameters. It just might have what you need.
kpkeerthi
March 26th, 2008, 07:27 AM
Hi I've been trying to write a simple backup script. I want to be able to automatically backup whenever my external hard drive is plugged in, but I don't know where to start, is there a way to execute something when a drive with a certain label is plugged in ?
Thanks
Jim
http://ubuntuforums.org/showthread.php?t=502864
wrightee
March 26th, 2008, 03:23 PM
#! /usr/bin/env python
import os
m="WD"
stat=os.system("mount | grep "+m)
if stat==0:
os.system("rsync -avh --exclude=vmware /home/wrightee /media/WD*/bak --delete")
else:
print "Drive not ready"
I do it like that, external drives are called WD (I use a couple), rsync handles everything I need. Not perfect, was my first ever python script, but works!
Ultra Magnus
March 26th, 2008, 08:36 PM
Awesome, the udev thing was exactly what I was looking for.
Thanks allot
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.