I've got data on my HDD that needs to be backed up. Lets say that it's everything in folder a. On a USB stick there's a copy of folder a, that should be updated automatically whenever the stick is mounted. How can this be done automatically?
Asked
Active
Viewed 798 times
1 Answers
1
Create a udev rule for when the drive is inserted, and run your backup routine (rsync or other procedure on the device).
This is a crude example to get you started.
The rule to call your backup script (/etc/udev/rules.d/10-local.rules):
ACTION=="add", RUN+="/bin/sh -c 'exec /home/userid/backupscript.sh & > /home/userid/Desktop/test.out'"
Replace userid above with your userid, or place the script in a different path.
The backup script:
#!/bin/bash
templine=/tmp/line.$$
backuproutine () {
# backup rountine goes here
timestamp=$(date)
message="This is the Backup noice."
device=$(mount | egrep "sd.1")
echo -e "$timestamp:$message\n$device" > $templine
cat $templine >> /home/userid/Desktop/backupnotice.txt
}
backuproutine
rm $templine
This is a crude script, but something to get you started.
This command will provide details on how to use the udev rules.
man udev
L. D. James
- 25,444