Our raid copys to one of two existing exteral drives in the system based of UUID. If one or the other is plugged in, it detects the drive and rsyncs the raid to the drive. Just plug in the drive, remove the other and take off site. That simple.
#!/bin/bash
UUID=$(ls /dev/disk/by-uuid | grep 9702537b-b84c-44cf-b417-eaaf95a6d240)
STATUS=$?
if [ $STATUS == 0 ] ; then
echo "detected:$UUID"
DEVICE=`ls /dev/disk/by-uuid/9702537b-b84c-44cf-b417-eaaf95a6d240 -l | awk -F/ '{print $NF}'`
if [ _"`grep /dev/$DEVICE /etc/mtab`" = _ ] ; then
echo "Device /dev/$DEVICE is not mounted"
mount -t ext3 -U 9702537b-b84c-44cf-b417-eaaf95a6d240 /mnt/usb_raid_rotate_1 -o rw,acl
if [ $? -eq 0 ] ; then
echo "Mounted $DEVICE"
fi
else
echo "Device /dev/$DEVICE is already mounted"
fi
echo '##############################'
echo ' raid_copy_rotate_2 '
echo '##############################'
rsync -avA --delete -e "ssh -p 34011 -i /root/.ssh/identity" --exclude=vdi/ root@x.x.x.x:/mnt/raid5/ /mnt/usb_raid_rotate_1/full_raid_copy/
if [ $? -eq 0 ]
then
echo "**************************** usb_raid_rotate_2 synced nicely"
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!! errors while syncing usb_raid_rotate_2"
fi
umount /mnt/usb_raid_rotate_1
if [ $? -eq 0 ]
then
echo "**************************** usb_raid_rotate_2 unmounted nicely"
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!! errors unmounting usb_raid_rotate_2"
fi
fi
UUID=$(ls /dev/disk/by-uuid | grep 668260a9-1f6e-4091-978e-89425ad33cf5)
STATUS=$?
if [ $STATUS == 0 ] ; then
echo "detected:$UUID"
DEVICE=`ls /dev/disk/by-uuid/668260a9-1f6e-4091-978e-89425ad33cf5 -l | awk -F/ '{print $NF}'`
if [ _"`grep /dev/$DEVICE /etc/mtab`" = _ ] ; then
echo "Device /dev/$DEVICE is not mounted"
mount -t ext3 -U 668260a9-1f6e-4091-978e-89425ad33cf5 /mnt/usb_raid_rotate_2 -o rw,acl
if [ $? -eq 0 ] ; then
echo "Mounted $DEVICE"
fi
else
echo "Device /dev/$DEVICE is already mounted"
fi
echo '##############################'
echo ' raid_copy_rotate_2 '
echo '##############################'
rsync -avA --delete -e "ssh -p 34011 -i /root/.ssh/identity" --exclude=vdi/ root@x.x.x.x:/mnt/raid5/ /mnt/usb_raid_rotate_2/full_raid_copy/
if [ $? -eq 0 ]
then
echo "**************************** usb_raid_rotate_2 synced nicely"
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!! errors while syncing usb_raid_rotate_2"
fi
umount /mnt/usb_raid_rotate_2
if [ $? -eq 0 ]
then
echo "**************************** usb_raid_rotate_2 unmounted nicely"
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!! errors unmounting usb_raid_rotate_2"
fi
fi