NOTE! This entry is for the B1 (BUBBA|server). It will work on a B2 as well, but the original instruction is probably better suited for the B2.
I thought I'd share the solution I'm using on my old but trusty B1 as well. It is a modified version of the one I use on my B2.
The reason the original solution doesn't work on a B1 is that this version of udev has no RUN option and therefor can't start the backup script. Upgrading udev is unfortunately not an option since this require a kernel upgrade as well and the kernel is kind of hard to upgrade (it could turn your bubba into a brick). The workaround is to let cron watch every minute for the device node to be created and then start the backup script. This instruction will guide you through the different steps. Reading the original post may help.
Install rsync or what ever backup program you want to use (the script uses rsync, change accordingly). Installing rsync or other external software require you enable the debian repository. Search this forum for instructions.
Create a configuration file,
/etc/default/usb_backup and put the following in it:
Code: Select all
#
# Array of folders to backup. Separate each entry with a space and make sure to use ""
# if name contain spaces.
#
BACKUP_FOLDERS=("/etc" "/home" "/root" "/var/lib" "/var/mail" "/var/spool/cron/crontab")
#
# Should script be allowed to start when device is connected?
# 0 = start when connected; 1 = don't start when connected
#
NO_START=0
#
# At what rate should LED flash during backup. Lower value means higher frequency
#
LED_RATE=4096
Create the script,
/etc/local/bin/usb_backup, and paste the following text in it:
Code: Select all
#!/bin/bash
#
# A simple backup solution for a BUBBA|server.
# Written by Johan Stenarson
#
CMD=usb_backup
CONFIG=/etc/default/$CMD
### Include user settings if there are any
test -f $CONFIG && . $CONFIG
### Test if script is already running
if [ -f /var/run/$CMD.pid ]; then
PID="`cat /var/run/$CMD.pid`"
for i in `ps x|grep $CMD|sed 's/^ *\([0-9]*\).*/\1/g'`; do
if [ "$i" == "$PID" ]; then
exit 2
fi
done
# Script not running but .pid file exists, continue
fi
echo $$ >/var/run/$CMD.pid
## Does settings allow script to start
if [ "$NO_START" != "0" ]; then
logger -t usb_backup "Not starting backup - edit $CONFIG and change NO_START to 0";
exit 0;
fi
### Mount point for USB device during backup
MOUNT_POINT=/tmp/backup_mount_point
### A fast flashing LED will indicate progress
/usr/sbin/gpioapp blink $LED_RATE $LED_RATE
### Mount device
mkdir -p $MOUNT_POINT && mount /dev/auto_backup_device $MOUNT_POINT
for FOLDER in ${BACKUP_FOLDERS[*]}
do
DEST=`dirname "$FOLDER"`
mkdir -p "$MOUNT_POINT/B1_autobackup$DEST"
rsync -a "$FOLDER" "$MOUNT_POINT/B1_autobackup$DEST"
done
### We're done, clean up
umount $MOUNT_POINT && rmdir $MOUNT_POINT
### Remove device node to prevent cron from starting us again
rm /dev/auto_backup_device
rm /var/run/$CMD.pid
/etc/init.d/led_on
The above script require the USB device has a node named '/dev/auto_backup_device', so we need to make sure udev will create one for us. To do this:
- 1) Connect your USB device to your bubba
- 2) Locate device in kernal log:
- 3) With the device node from previous step, run(replacing 'sdb' with the device node you got). This will show a list of attributes that identifies the device. Pick a couple from same section that appears to be unique (there aren't many to choose from).
- 4) Create a file /etc/udev/rules.d/010_backup.rules and put the attributes in it
Code: Select all
BUS=="scsi", SYSFS{vendor}=="Maxtor 6", SYSFS{model}=="L250R0", SYMLINK+="auto_backup_device"
This will create a device node named '/dev/auto_backup_device' when the USB disk is connected (you will ofcourse replace the attributes with the ones you picked).
Now that we know udev will create the device node, lets make cron monitor its existance and start the backup script when it exist. Create a file named
/etc/cron.d/usb_backup containing:
Code: Select all
* * * * * root test -b /dev/auto_backup_device && /usr/local/bin/usb_backup
That should do it. The script will start when you connect the disk. Note that cron verifies the existence of the node only once every minute so it may take up to one minute after you connect the device before the script actually starts. The LED will blink during the whole process and return to a solid state when backup is done.
/Johan