Yes, i can probably do this with hotplug, but its Fedora Core 2, and I gave up.
Note, you need to create the sfdisk.out before using this script like this:
sfdisk -d /dev/sda > /home/backup/sfdisk.out
#!/bin/sh
# Just in case
umount /mnt/backup
# Figure out the disk
for i in `ls /dev/sd?`
do
DISK=`fdisk -l $i | wc -l`
if [ $DISK -gt 0 ]; then
DISK=$i
break
fi
#echo $i
done
# Get number of linux partitions
PARTITIONS=`/sbin/sfdisk -l $DISK | /bin/grep Linux | /usr/bin/wc -l`
# If No linux partitions, try and create one.
if [ $PARTITIONS -lt 1 ]; then
echo "Creating partition"
/sbin/sfdisk -q $DISK < /home/backup/sfdisk.out
echo "Creating filesystem"
/sbin/mkfs.ext2 -q ${DISK}1
PARTITIONS=`/sbin/sfdisk -l $DISK | /bin/grep Linux | /usr/bin/wc -l`
fi
# If still no partitions, abort
if [ $PARTITIONS -lt 1 ]; then
echo "Couldn't create linux partition"
exit
fi
echo "Found $PARTITIONS Linux partitions"
/bin/mount -t ext2 ${DISK}1 /mnt/backup
DISK=`/bin/df | /bin/grep ${DISK}1 | /usr/bin/wc -l`
# If disk not present, abort
if [ $DISK -lt 1 ]; then
echo "Not available partitions"
exit
fi
cd /mnt/backup
/usr/bin/rsync --delete --quiet -ax / .
umount /mnt/backup