#!/bin/sh
#
# Copyright (c) Citrix Systems 2008. All rights reserved.
#

set -e
set -x

# Restore a backup to the other partition
. /etc/xensource-inventory
DEVICE=$BACKUP_PARTITION

if [ -z "$DEVICE" ]
then
     # Don't know where to put the backup!
     exit 2
fi

# Preserve the partition label when reformatting
LABEL=$(e2label "${DEVICE}" 2>/dev/null || echo "")
mkfs.ext3 -q -L "${LABEL}" "${DEVICE}"

TMP=`mktemp -d`

error () {
      trap - EXIT ERR
      umount $TMP || true
      rmdir $TMP || true
}

trap error EXIT ERR

mount $DEVICE $TMP
tar -C $TMP -xzp

# The installer checks for this file when looking for a backup partition.
touch $TMP/.xen-backup-partition

