Tuesday, February 17, 2009

backup up a dozen of windows PC's

There are many backup solutions out there. To get a second copy of all windows clients you could install software on each PC like Cobian, Mirrorfolder or Viceversa. And then let the data copy to a fileserver somewhere in the network. This works fine for a single PC, but if you have more than ten clients to configure, it gets quite hard to maintain.
I wanted a solution with the following features:
- centralized management of directories to backup and schedule.
- automated backup
- minimal software on the windows PC
- open source

What I did:
Installed Deltacopy on the windows PC's. This is basically a rsync server with a GUI. I created one big "rsync-share" which is the C: drive.
On the linux fileserver (a nslu2 with a big usb disk) I wrote some small scripts.
Here is an example:

#!/bin/bash

BCKHOST=mylaptop
HOSTUSER=backup
HOSTPASSFILE=/root/backup/passw/$BCKHOST
RSYNCPARMS="-avtol --stats --bwlimit=200 --delete"
DESTDIR=/home/share/deltacopy
SRCDIR1=/c_drive/DOCS
BCKLOG=/var/log/deltacopy/$BCKHOST.log


chmod 600 $HOSTPASSFILE

while test 1
do
while ! ping -c1 -w4 $BCKHOST > /dev/null
do
sleep 300
done
echo "DELTACOPY -- [`date`] $BCKHOST is up" >> $BCKLOG

sleep 200

echo "DELTACOPY -- [`date`] starting backup on $BCKHOST" >> $BCKLOG

rsync $RSYNCPARMS --password-file=$HOSTPASSFILE rsync://$HOSTUSER@$BCKHOST$SRCDIR1 $DESTDIR/$BCKHOST 1>> $BCKLOG 2>> $BCKLOG

echo "DELTACOPY -- [`date`] backup finished" >> $BCKLOG

while ping -c1 -w5 $BCKHOST > /dev/null
do
sleep 300
done
echo "DELTACOPY -- [`date`] $BCKHOST is down" >> $BCKLOG
done


For each host you'll have to make a copy of this script.
The script waits until the PC is on the network and then starts the rsync backup. When finished it waits until it's powered off. Then the scripts starts over again. At night a second script takes care of email notification, here it is:

#!/bin/bash

# usage: sendreport

REPORT=/var/log/deltacopy/$1.log
RECIPIENT=$2
DATESTAMP=`date | cut -b 1-10`

if [ ! -f $REPORT ]; then
SUBJECT="[$HOSTNAME] - MISSING backup for $1 on $DATESTAMP"
else
if ( `grep -q "rsync" $REPORT` || `grep -q "fail" $REPORT`); then
SUBJECT="[$HOSTNAME] - FAILED backup for $1 on $DATESTAMP"
else SUBJECT="[$HOSTNAME] - SUCCESSFUL backup for $1 on $DATESTAMP"
fi
fi

cat $REPORT | mail -s"$SUBJECT" $RECIPIENT


Et voila... simple and reliable.
Feel free to comment.

Baobab

What!? indeed: baobab. A colleage of mine told me this was some kind of remarkable tree, but it also turns out to be a little handy utlility.
With baobab you'll get a nice overview of all the directory sizes. You can also let this utility connect to a remote filesystem. The sector view is a bit akward at first but it's quite convenient. Requires gnome. An apt-get install shows that the package is to be replaced by gnome-utils, so chances are it's already on your linux box.