DSL based BACKUP/RESTORE solution


Forum: DSL Tips and Tricks
Topic: DSL based BACKUP/RESTORE solution
started by: CyberCod

Posted by CyberCod on Mar. 31 2007,15:24
------------------------------------------------
The project is working fine now using the
instructions in these first three posts.

I had just a couple typos to clear up, but
everything is tip top now.

Later revisions will be further along in
this thread.  I welcome anyone to post their
revisions.  I am trying to be as open-source
as I know how to be.
------------------------------------------------


I've used DSL to make an automated backup/restore solution.

This solution works in three parts:
  a two part automatic process started from the main hd install
  and a restore disk that can do the same as the first two parts
  and can also restore from a backup on the disk.


I will describe how I have mine set up, and post all the scripts involved,
and anyone who is interested is welcome to adjust the scripts to their
specific needs.

If you're unfamiliar with the scripting involved, i suggest you check out the thread where I hashed all this out.  It details the journey to getting this restore project working, as well as links to the tutorials and stuff that I read in order to come up with the script.

You can find that thread < HERE. >

The machine in question is a very old laptop... a Fujitsu 735Dx.


The machine specs are:
133Mhz Pentium 1
32MB ram
1.6GB Harddrive
CD-rom
no floppy or ethernet
wlan0 provided by usb wireless card.

First I partitioned the drive into 3 partitions.
hda1 is ext2 with about 850MB
hda2 is swap with 200MB
hda3 is ext2 with about 500MB

I did the HD install of DSL to hda1 with grub, and customized it and got everything set up like I like it.
I did a 2nd HD install of DSL on hda3 and for the most part left it alone.  I didn't install grub on the hda3 install because it wasn't needed.

So grub is pointing to hda1 at /boot/grub/menu.lst

Now for some of the scripts involved.

This script is in the user's home directory and its called .backupmode.sh
Its called up by an option in the fluxbox menu.

Code Sample

#!/bin/bash
#backup script

backup()
{
echo " "
echo " This process can take up to an hour"
echo " "
echo "System will reboot to enter automatic backup operations."
echo "If you started this by mistake, you have 10 seconds"
echo " to cancel this by pressing CTRL-C."

sleep 10
sudo cp /boot/grub/menu.lst_backupmode /boot/grub/menu.lst
sudo mount /dev/hda3 /mnt/hda3 2> /dev/null
sudo cp /mnt/hda3/opt/bootlocal.sh_backupmode /mnt/hda3/opt/bootlocal.sh
echo "Backup Mode boot process initialized"
sleep 10
echo "BEGINNING"
sleep 1
sudo reboot
}


echo " WELCOME TO THE SYSTEM BACKUP UTILITY"
echo " "
echo " This utility is designed to backup your system so that"
echo " in the event of a system malfunction, you can restore to"
echo " this point."
echo " "
echo " Everything will be backed up.  Even documents and personal"
echo " files.  It is wise to do this regularly, perhaps once a week."
echo " "
echo " The backup process is fully automatic, and will take almost an hour"
echo " so it is a good idea to start the backup just before bed, or when"
echo " you know you will not be needing your machine for a little while."
echo " "
echo " PLEASE SAVE ALL OPEN FILES BEFORE CONTINUING BACKUP!!!"
echo " "
echo "Press ENTER to continue..."
read throwaway
clear



echo "Would you like to reboot and run backup operations?"
echo "1. YES"
echo "2. NO"
read answer

case $answer in
1) backup
;;
*) exit
esac

done


As you can see, it does a couple things.  First it comes up with an explanation of whats
about to happen, then it gives the option of exiting.  If its not exited, then it does the
following things.

Code Sample

sudo cp /boot/grub/menu.lst_backupmode /boot/grub/menu.lst

This line copies an adjusted copy of menu.lst over top of menu.lst.
The adjustment is that the hda3 installation is at the top of the menu, so
it will be the system that is automatically booted into.

Code Sample

sudo mount /dev/hda3 /mnt/hda3 2> /dev/null

Mounts hda3


Code Sample

sudo cp /mnt/hda3/opt/bootlocal.sh_backupmode /mnt/hda3/opt/bootlocal.sh

This line copies an alternate version of hda3's bootlocal.sh onto it, called
bootlocal.sh_backupmode

The alternate version loads a script ( /backup/backup.sh on hda3) during the boot process

Lastly, the script reboots the machine.

Now upon reboot, the machine will boot to the hda3 install, and begin the /backup/backup.sh script.

There's another script called .restoremode.sh in the user's home directory that is pretty much the same except that the line
Code Sample

sudo cp /mnt/hda3/opt/bootlocal.sh_backupmode /mnt/hda3/opt/bootlocal.sh


is changed to
Code Sample

sudo cp /mnt/hda3/opt/bootlocal.sh_restoremode /mnt/hda3/opt/bootlocal.sh


and the text that is printed to the screen reflects that it is
a restore operation, not a backup operation.

the file bootlocal.sh_restoremode calls up the /backup/restore.sh script on hda3


backup.sh script is as follows
Code Sample




#!/bin/bash
# Backup Script

#make directory and mount partition hda1
mkdir hda1 2> /dev/null
mount /dev/hda1 /hda1
echo "Main partition mounted..."


#first thing is to restore the normal menu.lst on hda1 so that in
#the event of a reboot, it will boot to the normal system
sudo cp /hda1/boot/grub/menu.lst_normal /hda1/boot/grub/menu.lst

echo "reboot synced to main"
wait 2

clear
  echo " About to begin backup operations."
  echo "  Once this is started do not turn off your machine."
 


  echo "Performing BACKUP Operations..."
  echo "This can take up to an hour, please be patient."
echo " "
sleep 3

echo " "

echo "Deleting previous backup file."
echo " "
echo " "
#delete the old backup file
rm -f /hda1backup.tar.gz
echo "Building backup file /hda3/hda1backup.tar.gz"
echo " "
echo " "
echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"

#backup hda1 to the file hda1backup.tar.gz
tar -czvpsf /hda1backup.tar.gz hda1

clear
echo " "
echo "Operating System on hda1 is now backed up to the file"
echo "hda1backup.tar.gz on the backup partition (hda3)."
echo " "

#once that is complete, change bootlocal.sh to something else
# bootlocal.sh_reboot has the system automatically reboot before
# it gets all the way booted up so the hda3 system can't be messed with
cp /opt/bootlocal.sh_reboot /opt/bootlocal.sh

echo "System will begin reboot in 5 seconds"
sleep 4
echo "Rebooting now!"
sleep 1
#reboot to the main system
reboot  





Below is the script /backup/restore.sh on hda3
Code Sample


#!/bin/bash
# Restoration Script
mkdir hda1 2> /dev/null
mount /dev/hda1 /hda1
echo "Main partition mounted..."
sudo cp /hda1/boot/grub/menu.lst_normal /hda1/boot/grub/menu.lst
echo "reboot synced to main"
wait 2
clear
echo " "
  echo "  About to begin restoration operations."
  echo "  Once this is started do not turn off your machine."
  echo "Performing RESTORE Operations..."
  echo "This takes about half an hour, please be patient."
echo " "
sleep 3
echo " "
echo " "
echo " "
echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"

#this is the only line that is really any different from backup.sh
# it unpacks hda1backup.tar.gz to the hda1 partition.
tar -xvzf /hda1backup.tar.gz -C /

clear
echo " "
echo "Operating System on hda1 is now restored from to the file"
echo "hda1backup.tar.gz on the backup partition (hda3)."
echo " "
cp /opt/bootlocal.sh_reboot /opt/bootlocal.sh
echo "System will begin reboot in 5 seconds"
sleep 4
echo "Rebooting now!"
sleep 1
reboot  



Thats pretty much it for the automatic backup system, next post I'll detail how I made the backup/restore disk by placing backups of hda1 hda3 and the MBR on a remastered disk with a script to restore it all.

Posted by CyberCod on Mar. 31 2007,17:01
Ok,

This restore disk works for the situation in the previous post.
If you need it to work for your own custom setup, you'll have to change the script to reflect your own ideas.



I used VMware on my Ubuntu installation (on my main machine) to mess about with the remastering process so I wouldn't tank my dsl install on the old laptop.

So before I began all of this I had the following files already created and copied to a shared folder on my Ubuntu machine:

hda1backup.tar.gz  ---this file is the result of doing the automatic backup on the previous post.  It can be found on hda3 in the root directory.

hda3backup.tar.gz --- which I made after i had my  automated system backup in place and working properly by doing the following in terminal on my hda1 dsl on the laptop.
Code Sample

sudo su
mkdir /hda3
umount /dev/hda3
mount /dev/hda3 /hda3
cd /
tar -cvzpsf /hda3backup.tar.gz hda3


MBRbackup.bin ---located on the root directory of hda1, which I made by doing the command
Code Sample

sudo dd if=/dev/hda of=/MBRbackup.bin bs=1 count=512

from the hda1 dsl terminal of the laptop.



I ended up taking my remastering instructions from the page below.  
< http://www.linuxforums.org/desktop....le.html >

Most of the instructions weren't needed for my project, so I'll repost the steps below that I actually used.

I booted up to the dsl live disk iso in vmware with a virtual harddrive on IDE 0:1 that was formatted to ext2 for partition 1 and had enough space for the operation.  As well as a swap partition for the live disk session to use on hdb2.  The live disk should pick up the swap partition automatically.

I used hdb so it wouldn't confuse me with the backup operations which deal with "hda1"

To figure out how much space you need on hdb1, take the total size of your backup files and double it, and then add another 150 to 200 megs.

Here I cheated a little and did the partitioning of the virtual hard drive by loading up the virtual machine with an iso of Puppy Linux and using Gparted, but if you're familiar with partitioning using DSL, then more power to you.

If you're going to do this in a real situation (not in VMware) then you'll have to adjust the instructions below to reflect the actual partition you're going to use instead of hdb1, and the Samba portion of the instructions won't be necessary as you can just boot to your normal linux installation and burn the iso.  So adjust this stuff as you need to for your specific case.

Ok... once the live disk is booted up, open up a terminal and put in the following commands.

Code Sample

sudo su
mkdir /hdb1
mount /dev/hdb1 /hdb1


cd /hdb1
 #note that from here on out everything is done from /hdb1 directory

mkdir source newcd newcd/KNOPPIX
cp -Rp /cdrom/boot newcd
cp -Rp /cdrom/lost+found newcd
cp -Rp /cdrom/index.html newcd
cp -Rp /KNOPPIX/* source
cp -Rp /KNOPPIX/.bash_profile source




Ok, at this point, the /hdb1/source directory contains the same info as whats on the original live disk.

So at this point, I minimize the terminal.

I download the samba.dsl extension from MyDSL so I can copy my backup file from where I saved it on my desktop machine.

I mount up my samba share, then open emelfm in root mode.
In the left panel I browse to my mounted shared folder, and in the right I go to /hdb1/source.  The next step is to make a directory right pane called "backup" then enter it.

I then select my hda1backup.tar.gz file from the left pane and copy it to the right pane.

I do the same for hda3backup.tar.gz and MBRbackup.bin.

Once that is done, minimize emelfm as we'll use it again in a moment.

Now I open Beaver in root mode.  Root mode may not be necessary, but it didn't hurt.

Using Beaver in root mode, open up /hdb1/souce/opt/bootlocal.sh

add the following line to it
Code Sample

sudo /KNOPPIX/backup/CDbackup.sh

save it, and then open a new file.

Here' where the script comes in... its pretty big AND IT IS FINALLY COMPLETE!

If you wish to customize this process, this script is where to do it.

in the new file put the following:
Code Sample


#!/KNOPPIX/bin/bash
# CD Restoration Script


initialize()
{
title()
{
clear
echo " "
echo "                    Roslins Restore Disk"
echo "                           ver. 1.2 "
echo " "
echo " "
echo " "
echo " "
echo "                        by Jeff Smith "
echo "              straightshootincomputin@yahoo.com "
echo " "
echo " "
echo "                 Press Enter to continue..."
read throwaway
}

# this is the text that pops up when -=More Information=-
# is selected from the menu.
information()
{
clear
echo " "
echo "  Hello, and welcome to Roslins Restore Disk! "
echo " "
echo " This disk will help you to restore your laptop"
echo " to working condition with little hassel."
echo " "
echo " There are two options on the main menu for "
echo " restoring.  It is best to try Option 1 first and see"
echo " if that gives you the results you want."
echo " "
echo " "
echo " Press Enter to continue..."
read throwaway

clear
echo "Option 1 - Restore Last Backup"
echo " Option 1 restores from the last backup you made"
echo " using the BACKUP feature located in the right-click"
echo " menu on the desktop."
echo " "
echo " If possible, you should use the RESTORE feature from"
echo " that menu instead of using this disk."
echo " "
echo " Use Option 1 in the event that you cannot get to that "
echo " feature in the right-click menu."
echo " "
echo " Press Enter to continue..."
read throwaway

clear
echo "Option 2 - Full Restoration"
echo " Option 2 is for when you have really messed things up."
echo " "
echo " Option 2 will delete all information on your laptop"
echo " and restore it to the way it was when you first got it."
echo " "
echo " All personal files and downloads will be gone"
echo " but you will have a working system again."
echo " "
echo " Use Option 2 if Option 1 does not fix the problem."
echo "  "
echo " Press Enter to continue..."
read throwaway

clear
echo "Option 2 - Full Restoration (continued)"
echo " If Option 2 does not fix the problem, then you may"
echo " need to first restore the Master Boot Record (MBR),"
echo " which is Option 4.  Then come back after rebooting "
echo " and try Option 2 again, and it should work fine."
echo " "
echo " If none of this works, you may have a faulty"
echo " harddrive."
echo " "
echo " "
echo "  "
echo " Press Enter to continue..."
read throwaway




clear
echo "Option 3 - Make a new backup"
echo " Option 3 will backup your main installation on hda1"
echo " "
echo " If you have lost the ability to backup via your right-click"
echo " menu, you may not want to make this backup because doing"
echo " so will lock in the changes you've made to the right-click menu."
echo " Once you've backed up those changes, your only way of "
echo " putting that option back is by doing the full restoration "
echo " (Option 2) from this disk."
echo " You will still be able to restore from this new backup"
echo " by using this CD if you do not want the right-click option available"
echo " Press Enter to continue..."
read throwaway

}

mount_drives()
{
mkdir /hda1
mkdir /hda3
echo "Checking Filesystems"
fsck /dev/hda1
fsck /dev/hda3
sleep 2
clear
echo "Mounting partitions"
sudo mount /dev/hda1 /hda1
sudo mount /dev/hda3 /hda3
sleep 2
}

#this is function to reboot the machine
reboot_to_hd()
{
echo " "
echo " "
  echo " Please press ENTER to reboot."
read throwaway
echo "System will begin reboot in 5 seconds"
sleep 4
echo "Rebooting now!"
sleep 1
reboot  
}

# this is a function to make a new backup file
# on the partition hda3
backup_to_hda3()
{
clear
echo " "
  echo "Performing Backup Operations..."
  echo "This can take up to an hour, please be patient."
sleep 3
mount_drives
cd /
echo "Deleting previous backup file."
rm -f /hda3/hda1backup.tar.gz
echo "Building backup file /hda3/hda1backup.tar.gz"
echo " "
echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
tar -cvzpsf hda3/hda1backup.tar.gz /hda1
clear
echo " "
echo "Operating System on hda1 is now backed up to the file"
echo "hda1backup.tar.gz on the backup partition (hda3)."
echo " "
echo "You can restore this backup by using the RESTORE option"
echo "located in the right-click menu, or by selecting Option 1"
echo "from this disk."
reboot_to_hd
}


# this is a function to restore from a backup file
# that is located on the partition hda3
restore_from_hda3()
{
clear
echo " "
echo "Restoring from Harddrive backup"
echo "This will take a while, please be patient."
echo " "
echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
sleep 3
mount_drives
cd /hda3
tar -xvzf hda1backup.tar.gz -C /
clear
echo " "
echo "Operating System on hda1 is now restored from"
echo "hda1backup.tar.gz on hda3."
reboot_to_hd
}


warning()
{
clear
echo " "
echo " Please note that this will delete everything on the drive"
echo " before restoring from the original backup file."
echo " "
echo " Use this only if Option 1 does not work."
echo " "
echo "This machine will be reset to the state it was in when"
echo " you received it."
echo " Are you sure you want to do this?"
echo " 1. Yes"
echo " 2. No"
echo "Enter your choice: "
read warningchoice
case $warningchoice in
1) restore_from_permanent  
     ;;
*) echo "Returning to main menu"; sleep 2
esac
}



# this is a function to restore the MBR
# from a backup file on the CD
restore_mbr()
{
clear
echo " "
echo "Restoring Master Boot Record (MBR)"
dd if=/KNOPPIX/backup/MBRbackup.bin of=/dev/hda bs=1 count=512
echo " "
echo "Master Boot Record restored."
reboot_to_hd

}



restore_from_permanent()
{
clear
echo "Will shortly begin restoring from permanent backup file "
echo "located on this disk."
echo " "
echo "This will take a while, please be patient."
echo " "
echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
sleep 3
echo "Format hda1"
mkfs.ext2 /dev/hda1
clear
echo "Format hda3"
mkfs.ext2 /dev/hda3
clear
echo "Partitions formatted."
mount_drives
clear
echo "Beginning hda1 restore"
cd /KNOPPIX/backup
tar -xvzf hda1backup.tar.gz -C /
clear
echo "hda1 restore complete."
sleep 5
echo "Beginning hda3 restore"
tar -xvzf hda3backup.tar.gz -C /
clear
echo "hda3 restore complete."
sleep 5
clear
echo "Copying hda1backup.tar.gz to hda3"
cp /KNOPPIX/backup/hda1backup.tar.gz /hda3/hda1backup.tar.gz
sleep 2
clear
echo "Unmounting partitions"
sudo umount /dev/hda1
sudo umount /dev/hda3
echo " "
echo "Restoration Complete."
reboot_to_hd  
}


interrupt_trapper()
{
echo "Cannot exit script this way."
echo "To exit, select Option 5 or Option 6"
echo "from the Main Menu"
}


menu()
{
trap interrupt_trapper INT
clear
echo "                 MAIN MENU "
echo "  "
echo "Choose from one of the options below to begin"
echo "  "
echo "1. Restore Operating System from Harddrive Backup"
echo "2. Do a Complete Restore from Backup on this disk"
echo "3. Make a new backup of the system."
echo "4. Restore MBR"
echo "5. REBOOT"
echo "6. Exit to Live session"
echo " "
echo "   For more information on the presented options,"
echo "   just press ENTER without any number."
echo " "
echo "If you're ready to begin, just type the"
echo "number of your choice, and then press ENTER"
read choice
case $choice in
1) restore_from_hda3  
      ;;
2) warning
      ;;
3) backup_to_hda3
;;
4) restore_mbr
;;
5) reboot_to_hd
;;
6) exit
;;
  *) information
esac
}
}
#below is the main flow of the script
#everything else is a function.
initialize
title
while :; do
menu
done





Ok, once all that is in the untitled text file, in Beaver you need to save it as /hdb1/source/backup/CDbackup.sh

Then bring emelfm back up and change the newly made text file's permissions to be executable by right-clicking backup.sh and selecting "Properties" then "Permissions" and pushing in the "exec" buttons and hittin apply or ok or whatever.

Now minimize emelfm again.


Ok, now its ready to be made into an ISO.

So we go back to the terminal which should still be parked at /hdb1.

put in the following two commands.
be advised it takes a little while.

Code Sample


mkisofs -R source | create_compressed_fs – 65536 > newcd/KNOPPIX/KNOPPIX


Code Sample

mkisofs -no-pad -l -r -J -no-emul-boot -boot-load-size 4 –boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat -hide-rr-moved -o mydsl.iso newcd


When its done, it should poop you out a file called mydsl.iso in your /hdb1 directory.

Bring emelfm back up.  The left pane should still show your samba shared folder.  So just change the right pane to show /hdb1 and move your new ISO over to your shared folder.

Its is at this point that I made my snapshot in VMware.

At this point you can exit vmware and burn your new ISO.

When booting from the new disk, it never comes fully up to X, everything happens before that.  You do have the option though of booting on up to the live session if you like.

The backup.sh script is pretty well commented.

If you have any more questions about it, please feel free to ask.
If you discover any typos, lemme know asap if you please :)


In the next post I'll post every script I have that is involved with this process.

Posted by CyberCod on Mar. 31 2007,18:20
.backupmode.sh - this file is located in /home/dsl on hda1 installation

This is called by adding this line to the fluxbox menu
[exec] (BACKUP SYSTEM) {aterm -e /home/dsl/.backupmode.sh}

Code Sample


#!/bin/bash
#backup script

backup()
{
echo " "
echo " This process can take up to an hour"
echo " "
echo "System will reboot to enter automatic backup operations."
echo "If you started this by mistake, you have 10 seconds"
echo " to cancel this by pressing CTRL-C."

sleep 10
sudo cp /boot/grub/menu.lst_backupmode /boot/grub/menu.lst
sudo mount /dev/hda3 /mnt/hda3 2> /dev/null
sudo cp /mnt/hda3/opt/bootlocal.sh_backupmode /mnt/hda3/opt/bootlocal.sh
echo "Backup Mode boot process initialized"
sleep 10
echo "BEGINNING"
sleep 1
sudo reboot



}



echo " WELCOME TO THE SYSTEM BACKUP UTILITY"
echo " "
echo " This utility is designed to backup your system so that"
echo " in the event of a system malfunction, you can restore to"
echo " this point."
echo " "
echo " Everything will be backed up.  Even documents and personal"
echo " files.  It is wise to do this regularly, perhaps once a week."
echo " "
echo " The backup process is fully automatic, and will take almost an hour"
echo " so it is a good idea to start the backup just before bed, or when"
echo " you know you will not be needing your machine for a little while."
echo " "
echo " PLEASE SAVE ALL OPEN FILES BEFORE CONTINUING BACKUP!!!"
echo " "
echo "Press ENTER to continue..."
read throwaway
clear



echo "Would you like to reboot and run backup operations?"
echo "1. YES"
echo "2. NO"
read answer

case $answer in
1) backup
;;
*) exit
esac

done




.restoremode.sh - this file is located in /home/dsl on hda1 installation

This is called by adding this line to the fluxbox menu
[exec] (RESTORE SYSTEM) {aterm -e /home/dsl/.restoremode.sh}

Code Sample


#!/bin/bash
#restore script

restore()
{
clear
echo " "
echo " "

echo "   If you started this by mistake, you have 15 seconds"
echo "   to cancel this by pressing CTRL-C."
echo " "
echo "    This process takes about half an hour"
echo " "
echo "  Unless you cancel, the system will reboot and "
echo "  begin automatic restore operations."


sleep 15
sudo cp /boot/grub/menu.lst_backupmode /boot/grub/menu.lst
sudo mount /dev/hda3 /mnt/hda3 2> /dev/null
sudo cp /mnt/hda3/opt/bootlocal.sh_restoremode /mnt/hda3/opt/bootlocal.sh
echo "Restore Mode boot process initialized"
sleep 2
echo "BEGINNING"
sleep 1
sudo reboot



}


clear

echo " WELCOME TO THE SYSTEM RESTORE UTILITY"
echo " "
echo " This utility is designed to restore your system to the"
echo " state it was in when the last backup was made"
echo " "
echo " Everything will be restored.  Even documents you may have deleted"
echo " since then.  If you have messed this system up, this is the easiest"
echo " way to make it work again."
echo " "
echo " The restore process is fully automatic, and will take about half an hour"
echo " so it is a good idea to start the process just before bed, or when"
echo " you know you will not be needing your machine for a little while."
echo " "
echo " "
echo "Press ENTER to continue..."
read throwaway
clear


echo "Would you like to reboot and run restore operations?"
echo "1. YES"
echo "2. NO"
read answer

case $answer in
1) restore
;;
*) exit
esac

done





menu.lst_normal - This file is located in /boot/grub of the hda1 installation

It is used to replace menu.lst   It is used by the restore.sh and backup.sh scripts.
Code Sample

default 0
hiddenmenu
timeout 3

title Boot into Linux
kernel /boot/linux24 root=/dev/hda1 quiet vga=normal dma nofstab norestore  noscsi frugal

title Backup Mode
kernel /boot/linux24 root=/dev/hda3 quiet vga=normal dma nofstab norestore  noscsi frugal

title Repair Mode
kernel /boot/linux24 root=/dev/hda1 quiet vga=normal noacpi noapm noscsi nodma frugal 2 base




menu.lst_backupmode - This file is located in /boot/grub directory of the hda1 installation.

This file is used to replace menu.lst  It is used by .restoremode.sh and .backupmode.sh scripts.
Code Sample

default 0
hiddenmenu
timeout 3

title Backup Mode
kernel /boot/linux24 root=/dev/hda3 quiet vga=normal dma nofstab norestore  noscsi frugal

title Boot into Linux
kernel /boot/linux24 root=/dev/hda1 quiet vga=normal dma nofstab norestore  noscsi frugal

title Repair Mode
kernel /boot/linux24 root=/dev/hda1 quiet vga=normal noacpi noapm noscsi nodma frugal 2 base






bootlocal.sh_backupmode - this file is located in the /opt directory of the hda3 installation.

This file is used to replace hda3's bootlocal.sh. Its used by the .backupmode.sh script.

Code Sample


#!/bin/bash
# put other system startup command here
clear
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo "                          Starting BACKUP script..."
echo " "
echo " "
echo " "
echo " "
echo "                        Programmed by Jeff Smith "
echo "                   straightshootincomputin@yahoo.com         "
sleep 2
sudo /backup/backup.sh
/sbin/syslogd





bootlocal.sh_restoremode - this file is located in the /opt directory of the hda3 installation.

This file is used to replace hda3's bootlocal.sh. Its used by the .restoremode.sh script.
Code Sample


#!/bin/bash
# put other system startup command here
clear
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo "                          Starting RESTORE script..."
echo " "
echo " "
echo " "
echo " "
echo "                         Programmed by Jeff Smith "
echo "                   straightshootincomputin@yahoo.com         "
sleep 2
sudo /backup/restore.sh
/sbin/syslogd







bootlocal.sh_reboot - this file is located in the /opt directory of the hda3 installation.

This file is used to replace hda3's bootlocal.sh. Its used by the backup.sh and restore.sh scripts.
Code Sample


#!/bin/bash
# put other system startup command here
clear
echo " "
echo " "
echo " "
echo " "
echo " "
echo " Do not enter this system unless it is via the Backup/Restore "
echo " options available on the main installation."
echo " "
echo " corrupting this installation would make it impossible for you "
echo " to use the backup/restore functions "
echo " if you've lost the ability to restore via the right-click"
echo " menu, please use the Restore Disk and select Option 1"
echo " to restore the last backup you have made."
reboot






backup.sh - this file is located in the /backup directory of the hda3 installation.

It is used to do the backup operations.  It is called by bootlocal.sh_backupmode script.

Code Sample


#!/bin/bash
# Backup Script
  mkdir hda1 2> /dev/null
  mkdir hda3 2> /dev/null
  mount /dev/hda1 /hda1
  echo "Main partition mounted..."
  sudo cp /hda1/boot/grub/menu.lst_normal /hda1/boot/grub/menu.lst
  echo "reboot synced to main"
  wait 2
  clear
  echo " About to begin backup operations."
  echo "  Once this is started do not turn off your machine."
  echo "          Performing BACKUP Operations..."
  echo "This can take up to an hour, please be patient."
  echo " "
  sleep 3
  echo " "
  echo "Deleting previous backup file."
  echo " "
  echo " "
  rm -f /hda1backup.tar.gz
  echo "Building backup file /hda3/hda1backup.tar.gz"
  echo " "
  echo " This takes about an hour"
  echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
  tar -czvpsf /hda1backup.tar.gz hda1
  clear
  echo " "
  echo "Operating System on hda1 is now backed up to the file"
  echo "hda1backup.tar.gz on the backup partition (hda3)."
  echo " "
  cp /opt/bootlocal.sh_reboot /opt/bootlocal.sh
  echo "System will begin reboot in 5 seconds"
  sleep 4
  echo "Rebooting now!"
  sleep 1
  reboot  






restore.sh - this file is located in the /backup directory of the hda3 installation.

It is used to do the restoration operations.  It is called by bootlocal.sh_restoremode script.
Code Sample


#!/bin/bash
# Restoration Script
  mkdir hda1 2> /dev/null
  mount /dev/hda1 /hda1
  echo "Main partition mounted..."
  sudo cp /hda1/boot/grub/menu.lst_normal /hda1/boot/grub/menu.lst
  echo "reboot synced to main"
  wait 2
  clear
  echo " "
  echo "  About to begin restoration operations."
  echo "  Once this is started do not turn off your machine."
  echo "          Performing RESTORE Operations..."
  echo "This takes about half an hour, please be patient."
  echo " "
  sleep 3
  echo " "
  echo " "
  echo " "
  echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
  tar -xvzf /hda1backup.tar.gz -C /
  clear
  echo " "
  echo "Operating System on hda1 is now restored from to the file"
  echo "hda1backup.tar.gz on the backup partition (hda3)."
  echo " "
  cp /opt/bootlocal.sh_reboot /opt/bootlocal.sh
  echo "System will begin reboot in 5 seconds"
  sleep 4
  echo "Rebooting now!"
  sleep 1
  reboot  









CDbackup.sh    this one is for the remastered CD.  You place it in the /hdb1/source/backup directory during the remastering process.

It is called up by adding the following line to the bootlocal.sh file in the /hdb1/source/opt directory during the remastering process.
Code Sample

sudo /KNOPPIX/backup/CDbackup.sh




Code Sample


#!/KNOPPIX/bin/bash
# CD Restoration Script


initialize()
{
title()
{
clear
echo " "
echo "                    Roslins Restore Disk"
echo "                           ver. 1.2 "
echo " "
echo " "
echo " "
echo " "
echo "                        by Jeff Smith "
echo "              straightshootincomputin@yahoo.com "
echo " "
echo " "
echo "                 Press Enter to continue..."
read throwaway
}

# this is the text that pops up when -=More Information=-
# is selected from the menu.
information()
{
clear
echo " "
echo "  Hello, and welcome to Roslins Restore Disk! "
echo " "
echo " This disk will help you to restore your computer"
echo " to working condition with little hassel."
echo " "
echo " There are two options on the main menu for "
echo " restoring.  It is best to try Option 1 first and see"
echo " if that gives you the results you want."
echo " "
echo " "
echo " Press Enter to continue..."
read throwaway

clear
echo "Option 1 - Restore Last Backup"
echo " Option 1 restores from the last backup you made"
echo " using the BACKUP feature located in the right-click"
echo " menu on the desktop."
echo " "
echo " If possible, you should use the RESTORE feature from"
echo " that menu instead of using this disk."
echo " "
echo " Use Option 1 in the event that you cannot get to that "
echo " feature in the right-click menu."
echo " "
echo " Press Enter to continue..."
read throwaway

clear
echo "Option 2 - Full Restoration"
echo " Option 2 is for when you have really messed things up."
echo " "
echo " Option 2 will delete all information on your laptop"
echo " and restore it to the way it was when you first got it."
echo " "
echo " All personal files and downloads will be gone"
echo " but you will have a working system again."
echo " "
echo " Use Option 2 if Option 1 does not fix the problem."
echo "  "
echo " Press Enter to continue..."
read throwaway

clear
echo "Option 2 - Full Restoration (continued)"
echo " If Option 2 does not fix the problem, then you may"
echo " need to first restore the Master Boot Record (MBR),"
echo " which is Option 4.  Then come back after rebooting "
echo " and try Option 2 again, and it should work fine."
echo " "
echo " If none of this works, you may have a faulty"
echo " harddrive."
echo " "
echo " WARNING!"
echo " NEVER USE OPTION 4 ON ANY MACHINE BUT THE ONE"
echo " THAT THIS DISK IS MADE FOR. "
echo " DOING SO COULD CAUSE PERMANENT DAMAGE TO IT."
echo " "
echo " Press Enter to continue..."
read throwaway




clear
echo "Option 3 - Make a new backup"
echo " Option 3 will backup your main installation on hda1"
echo " "
echo " If you have lost the ability to backup via your right-click"
echo " menu, you may not want to make this backup because doing"
echo " so will lock in the changes you've made to the right-click menu."
echo " Once you've backed up those changes, your only way of "
echo " putting that option back is by doing the full restoration "
echo " (Option 2) from this disk."
echo " You will still be able to restore from this new backup"
echo " by using this CD if you do not want the right-click option available"
echo " Press Enter to continue..."
read throwaway

}

mount_drives()
{
mkdir /hda1
mkdir /hda3
echo "Checking Filesystems"
fsck /dev/hda1
fsck /dev/hda3
sleep 2
clear
echo "Mounting partitions"
sudo mount /dev/hda1 /hda1
sudo mount /dev/hda3 /hda3
sleep 2
}

#this is function to reboot the machine
reboot_to_hd()
{
echo " "
echo " "
  echo " Please press ENTER to reboot."
read throwaway
echo "System will begin reboot in 5 seconds"
sleep 4
echo "Rebooting now!"
sleep 1
reboot  
}

# this is a function to make a new backup file
# on the partition hda3
backup_to_hda3()
{
clear
echo " "
  echo "Performing Backup Operations..."
  echo "This can take up to an hour, please be patient."
sleep 3
mount_drives
cd /
echo "Deleting previous backup file."
rm -f /hda3/hda1backup.tar.gz
echo "Building backup file /hda3/hda1backup.tar.gz"
echo " "
echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
tar -cvzpsf hda3/hda1backup.tar.gz /hda1
clear
echo " "
echo "Operating System on hda1 is now backed up to the file"
echo "hda1backup.tar.gz on the backup partition (hda3)."
echo " "
echo "You can restore this backup by using the RESTORE option"
echo "located in the right-click menu, or by selecting Option 1"
echo "from this disk."
reboot_to_hd
}


# this is a function to restore from a backup file
# that is located on the partition hda3
restore_from_hda3()
{
clear
echo " "
echo "Restoring from Harddrive backup"
echo "This will take a while, please be patient."
echo " "
echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
sleep 3
mount_drives
cd /hda3
tar -xvzf hda1backup.tar.gz -C /
clear
echo " "
echo "Operating System on hda1 is now restored from"
echo "hda1backup.tar.gz on hda3."
reboot_to_hd
}


warning()
{
clear
echo " "
echo " Please note that this will delete everything on the drive"
echo " before restoring from the original backup file."
echo " "
echo " Use this only if Option 1 does not work."
echo " "
echo "This machine will be reset to the state it was in when"
echo " you received it."
echo " Are you sure you want to do this?"
echo " 1. Yes"
echo " 2. No"
echo "Enter your choice: "
read warningchoice
case $warningchoice in
1) restore_from_permanent  
     ;;
*) echo "Returning to main menu"; sleep 2
esac
}



# this is a function to restore the MBR
# from a backup file on the CD
restore_mbr()
{
clear
echo " "
echo "Restoring Master Boot Record (MBR)"
dd if=/KNOPPIX/backup/MBRbackup.bin of=/dev/hda bs=1 count=512
echo " "
echo "Master Boot Record restored."
reboot_to_hd

}



restore_from_permanent()
{
clear
echo "Will shortly begin restoring from permanent backup file "
echo "located on this disk."
echo " "
echo "This will take a while, please be patient."
echo " "
echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
sleep 3
echo "Format hda1"
mkfs.ext2 /dev/hda1
clear
echo "Format hda3"
mkfs.ext2 /dev/hda3
clear
echo "Partitions formatted."
mount_drives
clear
echo "Beginning hda1 restore"
cd /KNOPPIX/backup
tar -xvzf hda1backup.tar.gz -C /
clear
echo "hda1 restore complete."
sleep 5
echo "Beginning hda3 restore"
tar -xvzf hda3backup.tar.gz -C /
clear
echo "hda3 restore complete."
sleep 5
clear
echo "Copying hda1backup.tar.gz to hda3"
cp /KNOPPIX/backup/hda1backup.tar.gz /hda3/hda1backup.tar.gz
sleep 2
clear
echo "Unmounting partitions"
sudo umount /dev/hda1
sudo umount /dev/hda3
echo " "
echo "Restoration Complete."
reboot_to_hd  
}


interrupt_trapper()
{
echo "Cannot exit script this way."
echo "To exit, select Option 5 or Option 6"
echo "from the Main Menu"
}


menu()
{
trap interrupt_trapper INT
clear
echo "                 MAIN MENU "
echo "  "
echo "Choose from one of the options below to begin"
echo "  "
echo "1. Restore Operating System from Harddrive Backup"
echo "2. Do a Complete Restore from Backup on this disk"
echo "3. Make a new backup of the system."
echo "4. Restore MBR"
echo "5. REBOOT"
echo "6. Exit to Live session"
echo " "
echo "   For more information on the presented options,"
echo "   just press ENTER without any number."
echo " "
echo "If you're ready to begin, just type the"
echo "number of your choice, and then press ENTER"
read choice
case $choice in
1) restore_from_hda3  
      ;;
2) warning
      ;;
3) backup_to_hda3
;;
4) restore_mbr
;;
5) reboot_to_hd
;;
6) exit
;;
  *) information
esac
}
}
#below is the main flow of the script
#everything else is a function.
initialize
title
while :; do
menu
done





I believe that is all of them.

I'll be doing some proofreading in the next couple days to be sure I have it all copied right.  My brain is pretty dead at this point.

Comments and/or improvements are welcome.

Posted by CyberCod on April 01 2007,15:40
The backup CD is working wonderfully now.

I tested it out by using the Ultimate Boot CD to completely remove
the MBR.

I then restored the MBR via the custom restore cd and rebooted.
Coming back into the restore disk the second time, I selected the
complete restoration option.

This restored both the hda1 install, and the hda3 backup install.

The backup function in the fluxbox menu works properly.

Everything works wonderfully.

I encourage any of you to use this to suit your needs.

Keep in mind that hda1 need not be a DSL installation, so long as hda3 has enough space to keep a tar of hda1 when its packed up (consider the size it would take to tar it up when it is full).

And the .restoremode.sh and .backupmode.sh scripts can be called by other means than a fluxbox menu.

You can even put them in cron.

Thanks for your interest, and thanks go to the DSL dev team for making such a tiny but powerful distro!

--CyberCod--

Posted by CyberCod on April 06 2007,18:45
I'll be adding more features to this script, but I have some reading to do to improve my limited understanding of bash scripting.

If anyone has suggestions for the script, or helpful comments or links, Please feel free to post them.

Posted by CyberCod on Aug. 12 2007,16:05
Wow, 800 views.  Glad to see this is getting some use!

If anyone has any further customizations, feel free to add them in here.

Posted by infinitycircuit on Aug. 12 2007,16:31
This is a very interesting script!

One thing to suggest is that in Option 3, you mention that backing up at this point will not allow you to use the fluxbox menu icon to backup.  You could add in an option to use sed to remove the line that starts the backup from ~/.fluxbox/menu, if it exists.  For example:

Code Sample

BACKUP_MENU_ENTRY=`grep "BACKUP SYSTEM" /hda1/home/dsl/.fluxbox/menu`
sed -e 's/"$BACKUP_MENU_ENTRY"//'


I'm not a very proficient coder so this might not work/this might cause other problems, but I think it will work.

Similarly, you could add the option to exclude certain files from the backup.  For instance, a user might not want to back up their videos.  You could do this by replacing the tar command with:

Code Sample

find /hda1 > /tmp/files_to_backup.lst
echo "Please enter each file or folder you don't wish to backup on a separate line, ending with "EOF"."
cat << EOF > /tmp/files_to_avoid.lst
tar -C /hda1 -T /tmp/files_to_backup.lst -X /tmp/files_to_avoid.lst zxvpsf hda3/hda1backup.tar.gz


Those are some simple (maybe erroneous) suggestions that I think might help the script.

Posted by jpeters on Aug. 14 2007,07:41
At the top of the script:

sudo cp /boot/grub/menu.lst_backupmode /boot/grub/menu.lst

Where were _backupmode files created?

Posted by CyberCod on Sep. 07 2007,23:52
Quote (jpeters @ Aug. 14 2007,03:41)
At the top of the script:

sudo cp /boot/grub/menu.lst_backupmode /boot/grub/menu.lst

Where were _backupmode files created?

If memory serves, those files were kept in the /boot/grub folder of the first installation.  the point being that grub is pointed to /boot/grub/menu.lst on hda1.

menu.lst_backupmode is a modified copy of menu.lst that puts the 2nd install as the first boot option in the grub menu.

Posted by jpeters on Sep. 08 2007,05:03
Quote (CyberCod @ Sep. 07 2007,19:52)
If memory serves, those files were kept in the /boot/grub folder of the first installation

menu.lst_backupmode is a modified copy of menu.lst that puts the 2nd install as the first boot option in the grub menu.

There aren't any menu.lst_backupmode files in any of my grub installations.

Posted by CyberCod on April 05 2008,04:53
Quote (jpeters @ Sep. 08 2007,01:03)
There aren't any menu.lst_backupmode files in any of my grub installations.

You wouldn't have it on a default install, you have to create that file.

An example of how it should look is on the first page of this thread.

Posted by CyberCod on April 05 2008,06:20
Quote (infinitycircuit @ Aug. 12 2007,12:31)
One thing to suggest is that in Option 3, you mention that backing up at this point will not allow you to use the fluxbox menu icon to backup.  You could add in an option to use sed to remove the line that starts the backup from ~/.fluxbox/menu, if it exists.  For example:

Well, this option in the script backs up your current setup on hda1 just as it is.  If you have edited the fluxbox menu and removed or changed the backup/restore options, it is just telling you that these changes will be permanently saved in the hda3 backup, and short of re-adding them yourself, or restoring from the backup that is saved on the restore disk, they will stay changed.
Posted by CyberCod on July 12 2008,04:24
I've not been on here in a while... has anyone had any suggestions for improving these scripts?
Posted by CyberCod on Feb. 01 2010,06:44
Woot!  Just noticed this post has the most views of this sub-forum.  Probably the most popular thing I've done.
<pat on back> me </pat on back>

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.