Linux – Trigger off rsync by just plugging in a USB drive

hotpluglinuxrsyncusb

I'd like to know if it's possible to automatically mount, and fire up rsync to sync a USB drive with a directory? Specifically, I'd like to copy as much data as the drive can hold and only delete the oldest files if space is needed. I would assume I'd do something like this with a script, but my problem, is where to start! Any comments and suggestions appreciated.

Thank You

Best Answer

You are probably going to want to look into a Udev rule to launch a script. What's good about udev rules is you can lock down what usb drive is used for backup so not every usb drive fires it off.

First step is to get your udev rule going:

Here is a great tutorial on writing udev rules
and here is another

Then you can move on to your scripting aspect. The first link covers a bit of launching the script from udev so then you just need to call rsync from it.

man:rsync has a lot of information on usage.

Related Question