Skip to content

Instantly share code, notes, and snippets.

@endemics
Created February 23, 2010 00:31
Show Gist options
  • Save endemics/311709 to your computer and use it in GitHub Desktop.
Save endemics/311709 to your computer and use it in GitHub Desktop.
#!/bin/sh
# simple windows backup system
# I was fed up to continuously reinstall my mum's windows so I came up
# with this system.
# she has 3 partitions as follows:
# hda1- windows system partition (15GB)
# hda2- a swapless basic debian partition (20GB)
# hda3- windows data partition
#
# * windows is configured so the user data are on the windows data partition
#
# * on the debian partition, the script is installed as /root/winbackup.sh
# with rights 0777
#
# * the /etc/inittab file is modified so:
#1:2345:respawn:/sbin/getty 38400 tty1
# now says
#1:2345:respawn:/root/winbackup.sh
#
# * I have created a /data rep
#
# * the packages ntfs-3g and ntfsprogs are installed
#
# BUGS: sometimes (when the ntfs partition is unclean), ntfsclone exists
# and I can't seem to capture a non zero result
#
# change the windows system partition path below:
WINDOWS_PART=/dev/hda1
IMAGE=/data/xp.ntfs
ntfs_restore () {
echo "WARNING: this will replace the current windows system partition"
echo "if you have personal data on the system partition, it will be ERASED"
echo "ensure you have backed up everything before saying yes below"
echo "are you sure you want to restore? y/n"
read -n 1 -s ASK
case $ASK in
"y")
echo "restoring..."
echo ""
echo ""
/usr/sbin/ntfsclone -r -O $WINDOWS_PART $IMAGE
RES=$?
clear
if [ $RES -eq 0 ]; then
echo "restore correcly finished"
export CORRECT=1
else
echo "error while restoring"
echo "your system partition may be in an unstable state"
fi
;;
"*")
break
;;
esac
}
ntfs_backup () {
echo "backing up..."
echo ""
echo ""
/usr/sbin/ntfsclone -s -O $IMAGE $WINDOWS_PART
RES=$?
clear
if [ $RES -eq 0 ]; then
echo "backup successfully terminated"
export CORRECT=1
else
echo "error while backing up"
echo "WARNING: your previous backup was deleted, try backing up again"
fi
}
CORRECT=0
clear
while [ $CORRECT -eq 0 ]
do
clear
echo "###################################################"
echo " Windows backup system"
echo "###################################################"
echo ""
echo " 1- to restore windows from the backup image press r"
echo ""
echo " 2- to backup windows press b"
echo "(WARNING this will ERASE your previous backup)"
echo ""
echo " 3- to quit without modifications press q"
echo ""
echo "###################################################"
read -n 1 -s ASK
case $ASK in
"r")
ntfs_restore
;;
"b")
ntfs_backup
;;
"q")
reboot
;;
*)
echo "\"$ASK\" is an invalid option, press r, b or q"
;;
esac
done
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment