#!/bin/sh # # Author: Martti Kuparinen # # $Id: bak2win,v 1.8 2009-11-30 15:43:44 martti Exp $ # usage() { cat << EOF Usage: `basename $0` [-c] src dst where -c Uncompress the backup image with "bzcat" src is the backup image dst is the NTFS filesystem to restore Examples: `basename $0` /home/backup/windows.img /dev/sda1 Restore the Windows partition from a normal backup image. Note that this image can also be loopback mounted (e.g. to fetch a single file) with # mkdir /mnt/ntfsclone # sudo mount -t ntfs -o loop /home/backup/windows.img /mnt/ntfsclone `basename $0` -c /home/backup/windows.img.bz2 /dev/sda1 Restore the Windows partition from a compress backup image. Note that compressed backups can NOT be loopback mounted. EOF exit 1 } ARGV=`getopt ch ${*}` [ ${?} != 0 ] && usage ARGS= NEED_UNCOMPRESS="false" set -- ${ARGV} for i do case "${i}" in -c) ARGS="${ARGS} -c" NEED_UNCOMPRESS="true" shift ;; -h) usage shift ;; --) shift ;; esac done [ $# -ne 2 ] && usage if [ -z "`which ntfsclone 2> /dev/null`" ]; then echo "ERROR: ntfsclone not found!" if [ -r /etc/lsb-release ]; then . /etc/lsb-release if [ "${DISTRIB_ID}" = "Ubuntu" ]; then echo "" echo "You can fix this by running" echo "" echo "sudo apt-get install ntfsprogs" echo "" exit 1 fi fi fi if [ ! -f "${1}" ]; then echo "ERROR: ${1} not found!" exit 1 fi if [ ! -b "${2}" ]; then echo "ERROR: ${2} is not a valid block device!" exit 1 fi if [ `id -u` -ne 0 ]; then sudo $0 ${ARGS} $* exit $? fi # Get rid of password prompt before actual dump... sudo ls 2>&1 > /dev/null T1=`date` if ${NEED_UNCOMPRESS}; then bzcat "${1}" | sudo ntfsclone -r -O "${2}" - else sudo ntfsclone -O "${2}" "${1}" fi T2=`date` echo "" echo "Started: ${T1}" echo "Completed: ${T2}" echo "" exit 0