Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.