What we are doing here you could describe as an incremental backup,
only the changes in the files will be updated.
It's important to know that if you set it up to go hard drive -> memory stick and then change a file on the memory-stick and run the script, it will be overwritten with the file on the hard drive.
You could use -u in rsync to ignore files which are newer on the memory stick.
I guess it would be possible to run the script both ways with -u but still there are some limitations.
One step at the time.
To make it automatic we create an udev rule.
Plug in the memory-stick and look which device drive it's using (/dev/sdb, /dev/sdc ..)
- Code: Select all
dmesg
Mine is on /dev/sdc
Check vendor and model
- Code: Select all
udevinfo -q all -n /dev/sdc
For me it's:
model: DataTraveler 2.0
vendor: Kingston
Now we can create the udev rule.
- Code: Select all
sudo vim /etc/udev/rules.d/10-local.rules
and paste this line but replace it with your vendor and model.
SUBSYSTEMS=="scsi", ATTRS{vendor}=="Kingston", ATTRS{model}=="DataTraveler 2.0", RUN+="/usr/bin/usbbackup %k"
Create /usr/bin/usbbackup
- Code: Select all
sudo vim /usr/bin/usbbackup
and put whatever script you have in there.
Then
- Code: Select all
sudo chmod a+x /usr/bin/usbbackup
So that's pretty much the basics. How you do it is up to you
_________________________________________________________________________
A simpler solution is to put the file autorun in the root directory of the flash disk.
Activate scripts in gnome-volume-properties.
Add execute permissions to autorun:
- Code: Select all
sudo chmod +x autorun
Put your rsync script inside autorun.
Now every time you plug in your usbstick,
you will get a dialog that asks if you want to run the script.
Just added nautilus /media/disk to the script to also have a nautilus windows open displaying the flashdisk contents.