There are a lot of windows server backup tools, but one is already built in: Windows Server Backup
It’s not the most sophisticated backup tool but it has some advantages:
- it’s already installed
- it’s free
- it works
The goal of “my backup idea” was to make bare metal backups at night. No incremental backups or other fancy stuff. Of course this approach has a few drawbacks, but none of them were showstoppers. One important point was that the backup should be easy to take off site, in case of physical damage to the office or theft. The usual precautionary measures. Online backup was not possible due to bandwidth limitations. Additionally, theft of the backup device should not end in a disaster, losing valuable data being the biggest concern.
The hardware to do this job is fairly minimal. I did have a Pogoplug left over for tinkering which was sold for around 10$. It did get a treatment of archlinux and was ready to go. You can replace the Pogoplug with whatever device you prefer, there’s nothing specific about it, it just was at the right place at the right time to do the job.
Additionally to the “plug” I used two external 2.5″ hdds for the backups. One connected and one in a safe storage in another location. They would be swapped periodically. Backups would run nightly, so there was a fresh on site backup and a slightly dated offsite backup. To protect the data on the drive from being accessed, I decided to use LUKS. I won’t cover the LUKS setup here, as it has been described quite a few times, good reads are on the archlinux wiki and at cybercity.
The backup process is straight forward:
- mount the disk
- start samba to share the disk over the network
- run a bare metal backup
- stop samba and unmount the disk
I managed to write a few bash lines to do the job.
#!/bin/bash
function measure_used_space(){
fill_state=`df -H /mnt/my_backup/ | sed '1d' | awk '{print $5}' | cut -d'%' -f1`
echo $fill_state percent used
}
echo -------------------
echo `date`
# lights on
echo none > /sys/class/leds/status\:green\:health/trigger
echo default-on > /sys/class/leds/status\:blue\:health/trigger
echo preparing disk
# open sda1 with keyfile
/usr/sbin/cryptsetup -d=/etc/keys/hddkey luksOpen /dev/sda1 cryptvolume
# mount sda1
mount /dev/mapper/cryptvolume /mnt/backupdir/
echo starting samba
# start samba
systemctl start smbd.service
# lights ready
echo none > /sys/class/leds/status\:blue\:health/trigger
echo default-on > /sys/class/leds/status\:green\:health/trigger
# remove oldest backup while disc > 80% full
measure_used_space
while [ $fill_state -gt 80 ]; do
echo removing oldest backup
oldest_backup=`ls -d /mnt/backupdir/backup/WindowsImageBackup*|head -n1`
echo $oldest_backup
rm -rf $oldest_backup
measure_used_space
done
echo backup system ready
echo -------------------
This script mounts the disk, toggles the light on the plug, so you can see a backup is in process. It removes old backups if we’re running low on disk space. After that it just sits there and waits for the backup to start.
After Windows Server Backup did its magic, we unmount and stop everything, so that it is harder to mess with the stored data.
#!/bin/bash #mark backupentry date date >> /mnt/backupdir/backup/backupdisk* #rename dir now=`date +"%Y-%m-%d"` mv /mnt/backupdir/backup/WindowsImageBackup /mnt/backupdir/backup/WindowsImageBackup-$now # make read only so if samba is up again nobody can change the backup chmod -R 500 /mnt/backupdir/backup/WindowsImageBackup-$now # stop samba systemctl stop smbd.service sync # unmount sdb1 umount /mnt/backupdir # close luks /usr/sbin/cryptsetup luksClose /dev/mapper/cryptvolume # prepare unplug #eject /dev/sdb1 # lights out echo none > /sys/class/leds/status\:green\:health/trigger echo none > /sys/class/leds/status\:blue\:health/trigger
The script gives a timestamp to the backup, otherwise Windows Server Backup would consistently overwrite the previous backup, leaving us with only one backup per disk in total. It stops samba, unmounts the drive and switches the lights off, so that whoever is switching the usb harddrive can see, that there is no backup in progress.
The performance of the Pogoplug for this job is far from optimal, but it gets the job done. This bare metal backup runs during the night, while no one is working and backs up 60GB in 3 hours. Which is 5MB/s roughly.
And don’t forget to test the recovery process. 🙂
Nico Heid
Latest posts by Nico Heid (see all)
- Raspberry Pi Supply Switch, start and shut down your Pi like your PC - August 24, 2015
- Infinite House of Pancakes – code jam 2015 - July 13, 2015
- google code jam 2014 – magic trick - April 18, 2014
