#!/bin/bash

# Copyright 2009 Adam Goryachev (www.websitemanagers.com.au)
# Version:	1.0
# Date:		25th November 2009
# License:	GPL v2

fdisk -l /dev/sdb | grep sdb1
if [ $? != 0 ]
then
	echo "ERROR: Could not find /dev/sdb1"
	exit
fi

# Make sure it is umounted
df | grep sdb1
if [ $? == 0 ]
then
	umount /dev/sdb1
	df | grep sdb1
	if [ $? == 0 ]
	then
		echo "ERROR: Could not umount /dev/sdb1"
		exit
	fi
fi
partimage -f3 -b -c -d -o restore /dev/sdb1 /var/lib/backuppc/image/20090625/clean_install.000
mount -t ntfs-3g -o uid=103,gid=106 /dev/sdb1 /mnt/sdb1
df | grep sdb1
if [ $? != 0 ]
then
	echo "ERROR: Could not mount /dev/sdb1 after partimage restore"
	exit
fi

cd /mnt/sdb1
sudo -u backuppc /usr/share/backuppc/bin/BackupPC_tarCreate -h winserver -n -1 -s cdrive / | tar -xf -
cd -
umount /dev/sdb1


fdisk -l /dev/sdb | grep sdb5
if [ $? != 0 ]
then
	echo "ERROR: Could not find /dev/sdb5"
	exit
fi

# Make sure it is umounted
df | grep sdb5
if [ $? == 0 ]
then
	umount /dev/sdb5
	df | grep sdb5
	if [ $? == 0 ]
	then
		echo "ERROR: Could not umount /dev/sdb5"
		exit
	fi
fi
mkntfs -f /dev/sdb5

mount -t ntfs-3g -o uid=103,gid=106 /dev/sdb5 /mnt/sdb5
df | grep sdb5
if [ $? != 0 ]
then
	echo "ERROR: Could not mount /dev/sdb5 after format restore"
	exit
fi

cd /mnt/sdb5
sudo -u backuppc /usr/share/backuppc/bin/BackupPC_tarCreate -h winserver -n -1 -s ddrive / | tar -xf -
cd -
umount /dev/sdb5
exit

