Code:
#! /bin/bash
# Name: partition-copy.sh
# By: Jan Zumwalt - www.neatinfo.com
# Ver: August 22th, 2010
# About: Copies partition and support files using dd command
#
# Copyright:
# 1992-2010 by Jan Zumwalt, www.neatinfo.com
# This software is free and open to the public. You may use, copy,
# modify, distribute, and sell this program (and any variants)
# without restriction, so long as you do not restrict others from
# doing the same.
#
# History:
# 1992 - simple script for IBM AIX and Minix OS @20 lines
# 1995 - enhanced and re-designed for SUSE Linux OS @60 lines
# 1998 - enhanced and re-designed for Mandrake Linux OS @100 lines
# 2002 - log and re-designed for PcLinux OS @150 lines
# 2005 - verbose comments and info section @250 lines
# 2008 - modifiable variables to top, keybrd input, user modifiable @350 lines
# 2009 - error checks, self install and shortcut feature @450 lines
# 2010 - aesthetics, menus and aux system files capability @600 lines
#
# Future enhancements:
# *Calculate file save elapsed time - in beta testing
# Improve log format
# Ability to save session log with partition file
# Restore feature
# Better file compression
# Kill process feature
#
# code remarks:
# -e = enable interpretation of backslash codes
# -n = disable newline at end of line (i.e. user input prompt)
# ${VAR} can be used to separate a variable if no space is
# available in a string, ie "http://www.${WEB}.com"
# exit 1 = error, exit 0 = success
# +------------------------------------------------------+
# | These are the user modifiable variables. The |
# | "MENU" variables are for the partition menu. |
# +------------------------------------------------------+
PARTITION="/dev/sda6" # default partition to copy and save
PD="50gb PcLinux development" # description
MENU1="/dev/sda1" # menu item 1
MENU1D="75gb development XP" # description
MENU2="/dev/sda7" # menu item 2
MENU2D="100gb development data" # description
MENU3="/dev/sdb1" # menu item 3
MENU3D="75gb backup XP" # description
MENU4="/dev/sdb2" # menu item 4
MENU4D="400gb primary data" # description
MENU5="/dev/sdd0" # menu item 5
MENU5D="usb thumb drive" # description
MENU6="/dev/sdd1" # menu item 6
MENU6D="usb thumb drive" # description
MENU7=" " # menu item 7
MENU7D="un-assigned" # description
MENU8=" " # menu item 8
MENU8D="un-assigned" # description
MENU9=" " # menu item 9
MENU9D="un-assigned" # description
FILE_ID="-`date +%Y-%m-%d_%N`" # unique id so we can save many partitions
FILE_PATH="/media/data-400gb/partition-images/" # target path, needs a trailing slash
FILE_NAME="partition"
# ##########################################################
# ### END OF USER MODIFIABLE VARIABLES ###
# ### DO NOT MODIFY CODE BELOW THIS ! ###
# ##########################################################
# Pretty ANSI writing
OFF="\033[0m"
BOLD="\033[1m"
DIM="\033[2m"
YELLOW="\033[1;33m"
RED="\033[1;31m"
GREEN="\033[1;32m"
BLUE="\033[1;34m"
FkeyRead () # read 1 character from keyboard, char is in $ANSWER
{
oldstty=$(stty -g)
stty -icanon -echo min 1 time 1
ANSWER=$(dd bs=1 count=1 2>/dev/null)
stty "${oldstty}"
}
clear
echo -en "\n\t ,--------------------------------------------------,"
echo -en "\n\t | |"
echo -en "\n\t | $GREEN"'______ _ _ _ _ '"$OFF |"
echo -en "\n\t | $GREEN"'| ___ \ | | (_) | (_) '"$OFF |"
echo -en "\n\t | $GREEN"'| |_/ /_ _ _ __| |_ _| |_ _ ___ _ __ '"$OFF |"
echo -en "\n\t | $GREEN"'| __/ _` | `__| __| | __| |/ _ \| `_ \ '"$OFF |"
echo -en "\n\t | $GREEN"'| | | (_| | | | |_| | |_| | (_) | | | |'"$OFF |"
echo -en "\n\t | $GREEN"'\_| \__,_|_| \__|_|\__|_|\___/|_| |_|'"$OFF |"
echo -en "\n\t | $GREEN"' _____ '"$OFF |"
echo -en "\n\t | $GREEN"' / __ \ '"$OFF |"
echo -en "\n\t | $GREEN"' | / \/ ___ _ __ _ _ '"$OFF |"
echo -en "\n\t | $GREEN"' | | / _ \| `_ \| | | | '"$OFF |"
echo -en "\n\t | $GREEN"' | \__/\ (_) | |_) | |_| | '"$OFF |"
echo -en "\n\t | $GREEN"' \____/\___/| .__/ \__, | '"$OFF |"
echo -en "\n\t | $GREEN"' | | __/ | '"$OFF |"
echo -en "\n\t | $GREEN"' |_| |___/ '"$OFF |"
echo -en "\n\t | |"
echo -en "\n\t '--------------------------------------------------'"
echo -en "$OFF"
echo -en "\n\n\t\t$BOLD$RED by: Jan Zumwalt - NeatInfo.com"
echo -en "\n\t\t\t Ver-8/2010 $OFF"
echo -en "\n\n\t\t Press$YELLOW [ANY]$OFF key to continue... "
FkeyRead
clear
echo -en "\n"
echo -en "\t This program uses the dd command to copy a partition to\n"
echo -en "\t a file. Without this script, a typing mistake using the\n"
echo -en "\t dd command can cause all your data to be destroyed!\n"
echo -en "\n"
echo -en "\t This script allows you to carefully plan ahead, then\n"
echo -en "\t repeat the process fearlessly. It also makes a nice log.\n"
echo -en "\n"
echo -en "\t This script is currently set for...\n"
echo -en "\t default partition: $BOLD$PARTITION$OFF $PD\n"
echo -en "\t default file name: $BOLD$FILE_NAME$OFF\n"
echo -en "\t default file id: $BOLD$FILE_ID$OFF\n"
echo -en "\n"
echo -en "\t You will be given an opportunity to change the\n"
echo -en "\t$BOLD partition $OFF and $BOLD file $OFF name. Partition menu choices may\n"
echo -en "\t be changed by opening the script with a text editor and\n"
echo -en "\t editing variables near the beginning of this script."
echo -en "\n\n\t\t Press$YELLOW [ANY]$OFF key to continue... "
FkeyRead
while :
do
clear
echo -en "\n\n\n"
echo -en "\t .------------------------------------------------.\n"
echo -en "\t | $GREEN MAIN MENU $OFF |\n"
echo -en "\t |------------------------------------------------|\n"
echo -en "\t | Please select from one of these options. |\n"
echo -en "\t | |\n"
echo -en "\t |$YELLOW 1) Copy partition to file $OFF |\n"
echo -en "\t |$YELLOW 2) View file system $OFF (fdisk -l) |\n"
echo -en "\t |$YELLOW 3) Initialize logs and create a shortcut $OFF |\n"
echo -en "\t |$YELLOW 4) Info - brief instructions $OFF |\n"
echo -en "\t |$YELLOW 5) Quit - also q,n, or x $OFF |\n"
echo -en "\t '------------------------------------------------'\n"
echo -en "\n"
echo -en "\t$BOLD What would you like to do? 1,2,3,4,5 $YELLOW[1]$OFF "
FkeyRead
MENU_CHOICE=$ANSWER
case $MENU_CHOICE in
1|"") # The user selected "Copy partition to file"
while :
do
clear
echo -en "\n\n\n\n"
echo -en "\t .------------------------------------------------.\n"
echo -en "\t | $GREEN PARTITION MENU $OFF |\n"
echo -en "\t '------------------------------------------------'\n"
echo -en "\t \n"
echo -en "\t $YELLOW 1) $MENU1 $OFF $MENU1D \n"
echo -en "\t $YELLOW 2) $MENU2 $OFF $MENU2D \n"
echo -en "\t $YELLOW 3) $MENU3 $OFF $MENU3D \n"
echo -en "\t $YELLOW 4) $MENU4 $OFF $MENU4D \n"
echo -en "\t $YELLOW 5) $MENU5 $OFF $MENU5D \n"
echo -en "\t $YELLOW 6) $MENU6 $OFF $MENU6D \n"
echo -en "\t $YELLOW 7) $MENU7 $OFF $MENU7D \n"
echo -en "\t $YELLOW 8) $MENU8 $OFF $MENU8D \n"
echo -en "\t $YELLOW 9) $MENU9 $OFF $MENU9D \n"
echo -en "\t $YELLOW 0) Quit $OFF do you really want to quit?\n"
echo -en "\t \n"
echo -en "\t .-------------------------------------------------. \n"
echo -en "\t |$YELLOW [default] = $PARTITION $OFF $PD |\n"
echo -en "\t '-------------------------------------------------'\n"
echo -en "\n"
echo -en "\t$BOLD Partition$OFF to copy and save 1,2,3... or $YELLOW[default]$OFF "
FkeyRead
PART_CHOICE=$ANSWER
case $PART_CHOICE in
"") # The user selected [default] partition
# deafault partition is already set, so continue
break ;;
1) # The user selected menu item 1
PARTITION=$MENU1
break ;;
2) # The user selected menu item 1
PARTITION=$MENU2
break ;;
3) # The user selected menu item 1
PARTITION=$MENU3
break ;;
4) # The user selected menu item 1
PARTITION=$MENU4
break ;;
5) # The user selected menu item 1
PARTITION=$MENU5
break ;;
6) # The user selected menu item 1
PARTITION=$MENU6
break ;;
7) # The user selected menu item 1
PARTITION=$MENU7
break ;;
8) # The user selected menu item 1
PARTITION=$MENU8
break ;;
9) # The user selected menu item 1
PARTITION=$MENU9
;;
0) # The user selected menu item 1
echo -en "\n\n\n\n\t$GREEN OK! I am quiting, thanks for using$YELLOW Partion-Copy!$OFF\n"
echo -en "\n\t Press $YELLOW [ANY]$OFF key to exit... "
FkeyRead
echo -en "\n\n"
exit 1
;;
*) # anything else is invalid
clear
echo -en "\n\n\n\n"
echo -en "\t .-------------------------------------------------. \n"
echo -en "\t | | \n"
echo -en "\t | $BOLD$RED That was an incorrect choice! $OFF |\n"
echo -en "\t | Press $YELLOW [ANY]$OFF key to continue... |\n"
echo -en "\t | | \n"
echo -en "\t '-------------------------------------------------'\n"
echo -en "\t "
FkeyRead
;;
esac
done
clear
echo -en "\n"
echo -en "\t OK! Here we go...\n"
# see if target directory exist
if [ ! -d $FILE_PATH ]; then
echo -en "\n\t$RED *** Target file directory not found *** $OFF\n"
echo -en "\n\t *** I can not go on without it! ***\n"
echo -en "\n\t Should I try to create the directory I need $BOLD$FILE_PATH$OFF ? "
echo -en "\n\t (I can only create a single directory off an existing one)"
FkeyRead
case $ANSWER in
[Yy])
mkdir $FILE_PATH
echo -en "\n\n\t I made the target file directory..."
;;
*)
clear
echo -en "\n\n\t $RED I warned YOU that I needed it! $OFF"
echo -en "\n\t $BOLD I QUIT!... $OFF\n\n\n"
exit 1;;
esac
fi
# see if log directory exist
if [ ! -d $HOME/logs ]; then
echo -en "\n\n\t $RED *** Log directory not found *** $OFF\n"
echo -en "\n\t Should I create the directory I need for logs ($HOME/logs)? "
FkeyRead
case $ANSWER in
[Yy])
mkdir $HOME/logs
esac
fi
# choose file name
echo -en "\n\t$YELLOW Enter a file name, (no spaces or weird characters) $OFF"
read FILE_NAME
# see if user wants fdisk info saved
echo -en "\n\t$YELLOW Would you like fdisk info saved [y/n]? $OFF"
FkeyRead
DISK_INFO=$ANSWER
case $DISK_INFO in
[Yy])
fdisk -l $PARTITION > $FILE_PATH$FILE_NAME$FILE_ID.fdisk.txt
echo -en "\n\n\t I saved the fdisk info to $FILE_PATH$FILE_NAME$FILE_ID.fdisk.txt"
;;
*)
echo -en "\n\t No fdisk info saved..."
;;
esac
# see if user wants mtab (fstab) data saved
echo -en "\n\n\t$YELLOW Would you like mtab (fstab) data saved [y/n]? $OFF"
FkeyRead
MTAB_DATA=$ANSWER
case $MTAB_DATA in
[Yy])
cp /boot/grub/menu.lst $FILE_PATH$FILE_NAME$FILE_ID.mtab
echo -en "\n\n\t I saved mtab data to $FILE_PATH$FILE_NAME$FILE_ID.mtab"
;;
*)
echo -en "\n\t No mtab data saved..."
;;
esac
# see if user wants mbr data saved
echo -en "\n\n\t$YELLOW Would you like mbr image saved [y/n]? $OFF"
FkeyRead
MBR_DATA=$ANSWER
case $MBR_DATA in
[Yy])
dd if=$PARTITION of=$FILE_PATH$FILE_NAME$FILE_ID.mbr.img count=1 bs=512
echo -en "\n\n\t I saved the mbr image to $FILE_PATH$FILE_NAME$FILE_ID.mbr.img"
;;
*)
echo -en "\n\t No mbr image saved..."
;;
esac
# see if user wants grub menu data saved
echo -en "\n\n\t$YELLOW Would you like grub boot menu data saved [y/n]? $OFF"
FkeyRead
GRUB_DATA=$ANSWER
case $GRUB_DATA in
[Yy])
cp /boot/grub/menu.lst $FILE_PATH$FILE_NAME$FILE_ID.grub.menu.lst
echo -en "\n\n\t I saved grub menu data to $FILE_PATH$FILE_NAME$FILE_ID.grub.menu.lst"
;;
*)
echo -en "\n\t No grub data saved..."
;;
esac
clear
echo -en "\n\n\n"
echo -en "\n\t .-------------------------------------------------."
echo -en "\n\t | |"
echo -en "\n\t | $RED"' _ _ _ _ '"$OFF |"
echo -en "\n\t | $RED"' | | | | (_) | | '"$OFF |"
echo -en "\n\t | $RED"' | | | | __ _ _ __ _ __ _ _ __ __ _| | '"$OFF |"
echo -en "\n\t | $RED"' | |/\| |/ _` | `__| `_ \| | `_ \ / _` | | '"$OFF |"
echo -en "\n\t | $RED"' \ /\ / (_| | | | | | | | | | | (_| |_| '"$OFF |"
echo -en "\n\t | $RED"' \/ \/ \__,_|_| |_| |_|_|_| |_|\__, (_) '"$OFF |"
echo -en "\n\t | $RED"' __/ | '"$OFF |"
echo -en "\n\t | $RED"' |___/ '"$OFF |"
echo -en "\n\t | |"
echo -en "\n\t '-------------------------------------------------'"
echo -en "\n\n\t$YELLOW You are about to copy...$OFF\n"
echo -en "\n\t $GREEN$PARTITION $OFF"
echo -en "\n\t to..."
echo -en "\n\t $GREEN$FILE_PATH$FILE_NAME$FILE_ID.gz $OFF\n"
echo -en "\n\t Do you want to continue y/n$YELLOW [Y]$OFF? "
FkeyRead
case $ANSWER in
[QqNnXx]) # we are here because the user wanted to quit
clear
echo -en "\n\n"
echo -en "\t OK! I am quiting...\n"
echo -en "\n\t Press $YELLOW [ANY]$OFF key to exit... "
FkeyRead
echo -en "\n\n"
exit 1;;
*) # any other key allows us to proceed
;;
esac
clear
echo -en "\n\n\t OK! We are going to continue...."
# opportunity to add comment to log file
echo -en "\n\n\t$YELLOW You may now add a comment for the log file...$OFF\n"
echo -en "\t "
read ANSWER
echo -e "\t\t"$ANSWER >> $HOME/logs/partition-copy.log
# save backup starting time image = /boot/vmlinuz
echo -en "\t +-----------------------------------------------+\n"
echo -en "\t Backup start time = " `date`"\n"| tee -a "$HOME/logs/partition-copy.log"
echo -en "\t +-----------------------------------------------+\n"
echo -en "\t Backing up...\n"| tee -a "$HOME/logs/partition-copy.log"
# The actual backup is done here. Included are some possible options.
# These options are machine specific - here is some of mine...
# dd if=/dev/hda1 of=/dev/hdc1 # win partition
# dd if=/dev/hda7 of=/dev/hdc7 # linux partition
# dd if=/dev/hda of=/dev/hdc # entire IDE slot 1 drive to IDE slot 3 <default>
echo -en "\t Partition=$PARTITION\n"| tee -a "$HOME/logs/partition-copy.log"
echo -en "\t Path=$FILE_PATH\n" | tee -a "$HOME/logs/partition-copy.log"
echo -en "\t File name=$FILE_NAME\n"| tee -a "$HOME/logs/partition-copy.log"
echo -en "\t File ID=$FILE_ID.gz\n" | tee -a "$HOME/logs/partition-copy.log"
START_TIME=`date +%s`
dd if=$PARTITION bs=1024k | gzip > "$FILE_PATH$FILE_NAME$FILE_ID.gz"| tee -a "$HOME/logs/partition-copy.log"
END_TIME=`date +%s`
ELAPSED_MINUTES=`echo $((($END_TIME-$START_TIME)/60))`
echo -en "\t Elapased minutes: $ELAPSED_MINUTES" | tee -a "$HOME/logs/partition-copy.log"
# save backup ending time
echo -en "\n\t Backup end time = " `date`"\n"| tee -a "$HOME/logs/partition-copy.log"
# success - show log file and exit
echo -en "\t Script completed successfully.\n\n"| tee -a "$HOME/logs/partition-copy.log"
echo -en "\t *******************************************\n"
echo -en "\t *** Here is a copy of your log file ***\n"
echo -en "\t *******************************************\n"
cat $HOME/logs/partition-copy.log
echo -en "\n\n\t Press the$YELLOW [ANY]$OFF key to exit. "
FkeyRead
echo -en "\n\n"
exit 0;;
2) # show drive info
clear
echo -en "\n\n"
echo -en ",-------------------------------------------------------------------,\n" | pr -o5 -t
echo -en ". .\n" | pr -o5 -t
echo -en ". This is a listing of your MOUNTED media. You may have other .\n" | pr -o5 -t
echo -en ". media attached and available. The file system or devices ${YELLOW}do${OFF} .\n" | pr -o5 -t
echo -en ". ${YELLOW}not have to be mounted${OFF} to work.$BOLD The \"dd\" command that this .\n" | pr -o5 -t
echo -en ". program uses can be VERY dangerous.$OFF There is no way of knowing .\n" | pr -o5 -t
echo -en ". what the intent of the user is, and in less than 1 second .\n" | pr -o5 -t
echo -en ". permanent data loss will occur! So, please be very carfull! .\n" | pr -o5 -t
echo -en ". .\n" | pr -o5 -t
echo -en "'-------------------------------------------------------------------'\n" | pr -o5 -t
echo -en "\n" | pr -o5 -t
df -h -T | pr -o5 -t | cut -c1-75
echo -en "\n" | pr -o5 -t
fdisk -l | pr -o5 -t | cut -c1-75
echo -en "\n Press$YELLOW [ANY]$OFF key to return to main menu." | pr -o5 -t
FkeyRead
clear ;;
3) # set up program and create a shortcut
clear
echo -en "\n\t$YELLOW" `date`"$OFF" | tee -a "$HOME/logs/partition-copy.log"
echo -en "\n"
echo -en "\n\t$BOLD Checking for personal log directory... $OFF\n"
if [ ! -d $HOME"/logs" ] ; then # if log dir not made, create it
mkdir $HOME"/logs"
echo -en "\t Missing personal log dir, I made one at $HOME/logs\n"| tee -a "$HOME/logs/partition-copy.log"
else
echo -en "\t Found personal log dir at $HOME/logs\n"| tee -a "$HOME/logs/partition-copy.log"
fi
echo -en "\n\t$BOLD Checking for personal bin directory... $OFF\n"
if [ ! -d $HOME"/bin" ] ; then # if bin dir not made, create it
mkdir $HOME"/bin"
echo -en "\t Missing personal bin dir, I made one at $HOME/bin\n"| tee -a "$HOME/logs/partition-copy.log"
else
echo -en "\t Found personal bin dir at $HOME/bin\n"| tee -a "$HOME/logs/partition-copy.log"
fi
echo -en "\n\t$BOLD Checking for script in personal bin directory... $OFF\n"
if [ ! -f $HOME"/bin/partition-copy.sh" ] ; then # if prog not in bin dir, copy it there
cp $0 $HOME"/bin/partition-copy.sh" # copy myself to the bin dir
echo -en "\t I copied script to bin dir at $HOME/bin\n"| tee -a "$HOME/logs/partition-copy.log"
else
cp $0 $HOME"/bin/partition-copy.sh" # copy myself to the bin dir
echo -en "\t I overwrote script in bin dir at $HOME/bin\n"| tee -a "$HOME/logs/partition-copy.log"
fi
echo -en "\n\t$BOLD Checking script permissions, making executable... $OFF\n"
chmod ugo+x "$HOME/bin/partition-copy.sh" # make sure script will execute
echo -en "\t Confirmed script is executable at $HOME/bin\n"| tee -a "$HOME/logs/partition-copy.log"
echo -en "\n\t$BOLD Desktop shortcut... $OFF\n"
START_DIR=$PWD # save current dir
echo -en "\t Going to your desktop and creating shortcut$YELLOW Partition-Copy$OFF...\n"| tee -a "$HOME/logs/partition-copy.log"
cd $HOME"/Desktop" # goto desktop to make shortcut
# This next section of code creates the desktop shortcut
{
echo "[Desktop Entry]"
echo "Comment="
echo "Comment[en_US]="
echo "Encoding=UTF-8"
echo "Exec='$HOME/bin/partition-copy.sh'"
echo "GenericName="
echo "GenericName[en_US]="
echo "Icon=cantor"
echo "MimeType="
echo "Name=partition-copy"
echo "Name[en_US]=partition-copy"
echo "Path="
echo "StartupNotify=true"
echo "Terminal=true"
echo "TerminalOptions=\s--noclose"
echo "Type=Application"
echo "X-DCOP-ServiceType=none"
echo "X-KDE-SubstituteUID=false"
echo "X-KDE-Username="
} > "partition-copy.desktop"
chmod ugo+x "partition-copy.desktop" # make shortcut executable
cd $START_DIR # be nice and return to our original dir
echo -en "\t Created desktop shortcut...\n"| tee -a "$HOME/logs/partiton-copy.log"
echo -en "\n\t Press$YELLOW [ANY]$OFF key to return to main menu."
FkeyRead
clear
;;
4) # The user wants some information about the script
clear
echo -en "\n"
echo -en "\t .--------------------- $BOLD About This Program $OFF ---------------------.\n"
echo -en "\t . .\n"
echo -en "\t . This is a very brief explanation of how this program works. .\n"
echo -en "\t . This program will work with all file systems. They do not .\n"
echo -en "\t . have to be mounted to work. This program's primary use is to .\n"
echo -en "\t . copy a complete partition to a file (backup). This will .\n"
echo -en "\t . provide an exact byte for byte copy (including MS Win). .\n"
echo -en "\t . $YELLOW This program can be VERY dangerous.$OFF There is no way of .\n"
echo -en "\t . knowing what the users intent is. A typing error can cause .\n"
echo -en "\t . permanent data loss in less than 1 second! .\n"
echo -en "\t . .\n"
echo -en "\t . Most mother boards provide SATA, IDE, SCSII and USB ports .\n"
echo -en "\t . for data storage. UNIX controls drives and partitions using .\n"
echo -en "\t . alias names. Here are some examples... .\n"
echo -en "\t . IDE uses hda,hdb,hdc, and hdd .\n"
echo -en "\t . SATA drives use sda, sdb, etc .\n"
echo -en "\t . USB are sdd0, sdd1, sdd2 and so on .\n"
echo -en "\t . .\n"
echo -en "\t . Each partition on a drive can be designated by adding a .\n"
echo -en "\t . number. hda1 is the first partition on the first IDE drive, .\n"
echo -en "\t . hda3 is the third partition of the same drive. .\n"
echo -en "\t . .\n"
echo -en "\t . more... pg 1 of 4 .\n"
echo -en "\t '----------------------------------------------------------------'\n"
echo -en "\n\t Press $YELLOW [ANY]$OFF key to continue... "
FkeyRead
clear
echo -en "\n"
echo -en "\t .--------------------- $BOLD About This Program $OFF ---------------------.\n"
echo -en "\t . .\n"
echo -en "\t . $BOLD dd$OFF is the UNIX command to make a file or partition image. .\n"
echo -en "\t . The \"dd\" command uses$BOLD if$OFF (in file) and$BOLD of$OFF (out file) as file .\n"
echo -en "\t . system parameters. To completely copy the 1st IDE drive to .\n"
echo -en "\t . the 2nd drive, we would use this command... .\n"
echo -en "\t . $YELLOW dd if=/dev/hda of=/dev/hdb $OFF .\n"
echo -en "\t . .\n"
echo -en "\t . Because we did not give partition numbers, the whole 1st .\n"
echo -en "\t . drive will be copied to the entire 2nd drive. .\n"
echo -en "\t . To copy a specific partition we must use the partition .\n"
echo -en "\t . number. Suppose we would like to copy the 1st partition of .\n"
echo -en "\t . IDE-3 (the \"c\" drive) and have it go to partition 4 of the .\n"
echo -en "\t . same drive. We would use this command... .\n"
echo -en "\t . $YELLOW dd if=/dev/hdc1 of=/dev/hdc4 $OFF .\n"
echo -en "\t . .\n"
echo -en "\t . Be forwarned that if the two partitions are not the same .\n"
echo -en "\t . size, bad things can happen. You usually are all right if .\n"
echo -en "\t . you copy a small partition to a big one, but copying a big .\n"
echo -en "\t . one to a small one usually results in data corruption. .\n"
echo -en "\t . .\n"
echo -en "\t . more... pg 2 of 4 .\n"
echo -en "\t '----------------------------------------------------------------'\n"
echo -en "\n\t Press $YELLOW [ANY]$OFF key to continue... "
FkeyRead
clear
echo -en "\n"
echo -en "\t .----------------------------------------------------------------.\n"
echo -en "\t . .\n"
echo -en "\t . To make selecting the file systems easy, I made two .\n"
echo -en "\t . variables to hold the drive definitions. They are located .\n"
echo -en "\t . near the beginning of this script. Here is how the .\n"
echo -en "\t . actual \"dd\" command looks using variables... .\n"
echo -en "\t . $YELLOW dd if=\$PARTITION of=\$FILE_ID $OFF .\n"
echo -en "\t . .\n"
echo -en "\t . UNIX is very generious in file system support, so this .\n"
echo -en "\t . script can be used for just about any type of storage .\n"
echo -en "\t . device. I have not tried other devices such as memory cards, .\n"
echo -en "\t . but I can not see any reason they should not work just as .\n"
echo -en "\t . well. .\n"
echo -en "\t . .\n"
echo -en "\t . more... pg 3 of 4 .\n"
echo -en "\t '----------------------------------------------------------------'\n"
echo -en "\n\t Press $YELLOW [ANY]$OFF key to continue... "
FkeyRead
clear
echo -en "\n"
echo -en "\t .----------------------------------------------------------------.\n"
echo -en "\t . Here are some examples I use with my 250gb development sys. .\n"
echo -en "\t . To mirror my entire drive \"A\" to drive \"C\" .\n"
echo -en "\t . $YELLOW PARTITION=/dev/hda $OFF .\n"
echo -en "\t . $YELLOW FILE_ID=/dev/hdc $OFF .\n"
echo -en "\t . .\n"
echo -en "\t . To save the Windows XP OS on drive \"A\" partition 1 to a file .\n"
echo -en "\t . with the date i.e \"partition-image-2010-06-04\" .\n"
echo -en "\t . $YELLOW PARTITION=/dev/hda1 $OFF .\n"
echo -en "\t . $YELLOW FILE_ID=/media/data/partition-image-\`date +%Y-%m-%d\`$OFF .\n"
echo -en "\t . .\n"
echo -en "\t . At the shell prompt, type$YELLOW man fdisk$OFF for some .\n"
echo -en "\t . interesting information. I hope this is of some use :) .\n"
echo -en "\t . .\n"
echo -en "\t . $BOLD Jan Zumwalt - NeatInfo.com $OFF .\n"
echo -en "\t . .\n"
echo -en "\t . pg 4 of 4 .\n"
echo -en "\t .----------------------------------------------------------------.\n"
echo -en "\n\t Press $YELLOW [ANY]$OFF key to continue... "
FkeyRead
clear ;;
5|[QqNnXx]) # we are here because the user wanted to quit
clear
echo -en "\n\n"
echo -en "\t OK! I am quiting...\n"
echo -en "\n\t Press $YELLOW [ANY]$OFF key to exit... "
FkeyRead
echo -en "\n\n"
exit 1;;
*) # the user's response does not make sense so...
clear
echo -en "\n\n"
echo -en "\t\t$BOLD Please enter ${YELLOW}1,2,3,4,5 $OFF \n"
echo -en "\n\t Press $YELLOW [ANY]$OFF key to try again... "
FkeyRead
echo -en "\n\n"
clear ;;
esac
done
exit 1