I haven't bothered with offsite backups. I don't need to because I live in Florida and it's not like we ever get hurricanes or anything like that.
I have a 3ware raid card in my 10.04 box with 4 drives in raid 5, as well as an eSATA drive. I export a TB of the RAID array and a TB from the iSCSI drive via iSCSI to two 2k8 servers running in Virtualbox VMs. In the Windows VMs, DFS mirrors the data to the two mountpoints. I export those shares to a Z: drive which maps on login. I set up the free MicrosoftSyncToys powertool to mirror the local My Documents directories to the Z: drive. When SyncToy is run, and the data is backed up in two places.
I have another esata drive which mirrors my home partition every night. This is slightly complicated because I have a couple dozen virtual machines that could be running (it's usually less than 10), so what I wanted was a way to pause any VMs that might be running, back everything up, then unpause. Here's the script I wrote to do that.
#!/bin/bash
#
# nightly_backup: Script to pause any virtual machines that are running,
# do an rsync backup, then unpause the virtual machines. Set the SRCE
# and DEST variables below, as well as the USER variable. Script assumes
# that $DEST is a separate partition. If this is not the case for you,
# comment out the line _mount_check below.
#
# Sample cron entry:
# 30 04 * * * /usr/local/bin/nightly_backup &>>/var/log/nightly_backup.log
#
# Sample /etc/logrotate.d/nightly_backup file
# /var/log/nightly_backup.log {
# monthly
# missingok
# rotate 4
# compress
# }
#
# --exclude-from file syntax:
# Copy directory but not its contents:
# + Cache/
# - **/Cache/**
#
# Do not copy (file or directory)
# - .gvfs
#
# $Id: nightly_backup,v 1.1 2011/12/03 19:23:15 doodleboy Exp kevin $
PATH=/bin:/usr/bin
USER=doodleboy
SRCE=/home
DEST=/archive
ARGS="-aHS --delete --stats --exclude-from=/usr/local/bin/rsync_exclude"
# Function to pause or resume running virtual machines
_pause-resume() {
ARG=$1
VMS=$(su - $USER -c "vboxmanage --nologo list runningvms")
if [ -n "$VMS" ]; then
printf "$VMS\n" | while read VM; do
VM=${VM%% \{*}
printf "Running $ARG on $VM...\n"
su - $USER -c "vboxmanage --nologo controlvm $VM $ARG"
done
else
printf "No VMs are running.\n"
fi
}
# Abort backup if $DEST partition is not mounted
_mount_check() {
if mount | grep -w "$DEST" &>/dev/null; then
printf "$DEST is mounted. Proceeding with backup.\n"
else
printf "$DEST is not mounted. Aborting backup.\n"
printf "*** $(date): Aborting nightly backup ***\n\n"
exit 1
fi
}
# Start banner
printf "*** $(date): Starting nightly backup ***\n"
# Make sure $DEST is mounted
# Comment out _mount_check if $DEST is not a partition
_mount_check
# Pause virtual machines
_pause-resume pause
# Flush pending writes
sync
sleep 3
# Do the backup
rsync $ARGS $SRCE $DEST
# Resume virtual machines
_pause-resume resume
# Exit banner
printf "*** $(date): Finished nightly backup ***\n\n"
I wrote another script to email me the status of my raid array every night. Admittedly this is only useful if you have a 4-drive 3ware card, but it could be adapted to other hardware. Here it is:
#!/bin/bash
PATH=/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin
RAID=$(tw_cli /c4 show)
U0=$(echo "$RAID" | awk '/^u0/ {print $3}')
P0=$(echo "$RAID" | awk '/^p0/ {print $2}')
P1=$(echo "$RAID" | awk '/^p1/ {print $2}')
P2=$(echo "$RAID" | awk '/^p2/ {print $2}')
P3=$(echo "$RAID" | awk '/^p3/ {print $2}')
BB=$(echo "$RAID" | awk '/^bb/ {print $4}')
for status in "$U0" "$P0" "$P1" "$P2" "$P3" "$BB"; do
if [ "$status" = "OK" ]; then
SUBJECT="RAID Status OK"
elif [ "$status" = "VERIFYING" ]; then
SUBJECT="RAID Status VERIFYING"
break
else
SUBJECT="ISSUES with RAID Array!!!"
break
fi
done
catEOF | mailx -s "$SUBJECT" someone@somesite.com &
$RAID
--
The fortune for today is:
$(/usr/games/fortune)
EOF