Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Sunday, July 13, 2025

File: [Platon] / scripts / shell / Windows-backup / RestoreWindows.sh (download)

Revision 1.2, Tue Mar 16 19:51:05 2004 UTC (21 years, 4 months ago) by rajo


Changes since 1.1: +2 -2 lines

Changed email address from <8host AT pauli.fmph.uniba.sk> to <rajo AT platon.sk>

#!/bin/sh

#
# /etc/inid.d/RestoreWindows.sh
#
# Script used for restoring Windows image backup e.g. from CD-ROM
#

# Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2003 Platon SDG
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# $Platon: scripts/shell/Windows-backup/RestoreWindows.sh,v 1.1 2003/01/24 20:16:39 rajo Exp $
#

#
# To restore your Windows, boot linux with these parameters
# (GRUB /boot/grub/menu.lst example, for others bootloaders
# read documentation of your bootloader):
#
# title Restore Windows
# password <YOUR-SECRET-PASSWORD>
# kernel (hd0,4)/boot/vmlinuz-2.4.19-xfs-OW init=/etc/init.d/RestoreWindows root=/dev/hda5 rw
# initrd (hd0,4)/boot/initrd-2.4.19-xfs-OW
#

# Ignore signals - security!
# TODO: Think also about 'Magic SysRg Key' 
trap '' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

# Log
mount /proc
mount -o remount,rw /
echo "`date` -- `cat /proc/cmdline`" >> /RestoreWindows.log
chown root.root /RestoreWindows.log
chmod 600 /RestoreWindows.log

#
# User setup:
#
# {{{

# here specify your Windows partition, which will be overwriten
# with backup
# VERY IMPORTANT -- be CAREFULL !!
RESTORE_PARTITION="/dev/hda1"

BACKUP_DRIVE="/cdrom"
BACKUP_IMAGE_DIR="$BACKUP_DRIVE/Windows-image-backup-03-01-22/"
IMAGE="$BACKUP_IMAGE_DIR/Windows-image-backup.img.bz2"
PACKER="bzip2"
UNPACKER="bunzip2"

# here set md5sum of allowed backup
IMAGE_MD5SUM="9ff855b712508d71705230a2b0ad34a4"

# Here add list of files, which you will save
# use '' for files with special chars, better for all files
FROM_DRIVE="/c"
TO_DRIVE="/d"

SAVE_DATA="$FROM_DRIVE/Moje dokumenty/
$FROM_DRIVE/Program Files/WhereIsIt/Katalog"

#
# End of user setup
# }}}


echo; echo
echo "Do you wish to restore Windows? [yes/N]"
echo "Answer 'yes' to restore"
read answer
if [ "X$answer" != "Xyes" ]; then
    reboot
fi

echo "Mounting $BACKUP_DRIVE, $FROM_DRIVE, $TO_DRIVE"
mount "$BACKUP_DRIVE"
mount "$FROM_DRIVE"
mount "$TO_DRIVE"

# test, ci je zaloha povolena: {{{
if [ -r "$IMAGE.md5sum" ]; then
    CD_MD5SUM="`cut -d ' ' -f 1 $IMAGE.md5sum`"
else
    echo "File $IMAGE.md5sum not found, can't restore Windows ..."
    sleep 10
    reboot
fi

echo "Testing backup ..."
if [ "X$IMAGE_MD5SUM" != "X$CD_MD5SUM" ]; then
    echo "Usage of these backup is not allowed !!"
    echo "rebooting ..."
    sleep 10
    reboot
fi
if [ -r "$IMAGE" ]; then
    CD_MD5SUM="`md5sum $IMAGE | cut -d ' ' -f 1`"
else
    echo "File $IMAGE not found, can't restore Windows ..."
    sleep 10
    reboot
fi
if [ "X$IMAGE_MD5SUM" != "X$CD_MD5SUM" ]; then
    echo "Windows backup is probably bad, can't use it..."
    echo "rebooting ..."
    sleep 10
    reboot
fi
# }}}

# Backup data: {{{
echo "Creating backup of needed data"
cd /
# we must save list of files to file, because there is no way
# how to store filenames containig spaces to variable
RETVAL=0
echo "$SAVE_DATA" > /files \
&& tar cvf $TO_DRIVE/DataBackup.tar --files-from=/files
RETVAL=$?
rm -f /files
if [ $RETVAL -ne 0 ]; then
    echo "Can't save data, please free some space on $TO_DRIVE ...";
    sleep 10;
    reboot;
fi

# }}}

echo "Unmounting $RESTORE_PARTITION"
umount "$RESTORE_PARTITION"
echo "Writing image to disc, please wait ..."
RETVAL=0
$UNPACKER -c -f "$IMAGE" | dd "of=$RESTORE_PARTITION"
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
    echo "Error writing image to disc ... ehmm?? (error $RETVAL)"
    sleep 20;
    reboot
fi

RETVAL=0
echo "Restoring saved data..."
cd /
mount "$RESTORE_PARTITION"
tar xvf $TO_DRIVE/DataBackup.tar
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
    echo "Error restoring data .. ehmm?? (error $RETVAL)"
    sleep 20
else
    echo "`date` -- OK -- `cat /proc/cmdline` " >> /RestoreWindows.log
    echo "OK, restarting in 10 seconds ..."
    sleep 10
fi

reboot

# vim: ts=4
# vim600: fdm=marker fdl=0 fdc=3


Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top