4

to keep up on my backups I want to run a specific rsync command when I insert a specific sata hard drive(s) into any or all of my hotswap bays. Would this be done using uuids somehow to keep track of the drives? whenever I search I find udev for usb drives, can this work here as well?

1 Answer 1

2

I use a simple udev rule for this. The backup drive is marked with a specific volume label (use tune2fs to set it). The udev rule starts a script:

$ cat /etc/udev/rules.d/90-backup.rules 
ACTION=="add", ENV{ID_FS_LABEL}=="backup", RUN+="/usr/local/bin/backup.sh"

(you can use ENV{ID_FS_UUID}="some-uuid" if you'd prefer not to use volume labels)

The script just runs the rsync:

$ cat /usr/local/bin/backup.sh
#!/bin/bash

mnt=/media/backup

(
mount $mnt
rsync -avx --exclude lost+found /home/ $mnt/backup/
umount $mnt
) > /dev/null 2>&1 &

udev expects the RUN="" command to be short-lived, so the script runs the rsync in the background.

This will work for any type of drive and/or interface - as long as udev gets notification that the drive has been added.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .