LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-22-2007, 07:55 AM   #31
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,605

Rep: Reputation: 53

44 A Quick Introduction to Bash Programming - Part 2
43 A Quick Introduction to Bash Programming - Part 1
see
http://www.codecoffee.com/tipsforlinux/index-linux.html

EDIT:
forgot to tell you there is a "dialog"
feature of bash that allows question box to pop up in txt mode

Last edited by Emmanuel_uk; 03-23-2007 at 04:00 AM.
 
Old 03-24-2007, 09:30 PM   #32
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
I'm taking a little time to study those scripting tutorials.

I'll be resuming action on the project once I feel I have a firm grip on the basics of scripting.

Thanks for the links!
 
Old 03-25-2007, 05:39 PM   #33
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
Ok, after doing some reading, I've come up with the script below.


I've still not done the "dd" portion of it... I'm getting my partitions on the laptop set up properly before I do that.

But so far it looks good to me...

Any thoughts?

I'm thinking if I work on it some more, I can make it so that the user can enter in the partitions they wish to backup and where to store the backup... but that'll be later. This project is pretty specific in its scope. A young girl who's new to Linux.

Doing that would make it a general purpose backup disk though... I'd probably need to ditch the ondisk backup file... hmmm... many things one can do here.

I've not tested this script out, so if anyone would care to proofread it for me, I'd appreciate it.




Code:
#!/bin/bash
# Restoration Script

backup_to_hda3()
{
	clear
	echo " "
        echo "Performing Backup Operations..."
        echo "This may take a while, please be patient." 
	sleep 3
	mkdir hda1
	mkdir hda3
	mount /dev/hda1 /hda1
	mount /dev/hda3 /hda3
	echo "Deleting previous backup file."
	rm -f /hda3/hda1backup.tar.gz
	echo "Building backup file /hda3/hda1backup.tar.gz"
	echo "This will take several minutes."
	echo " "
	echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
	tar -czpsf 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 "System will begin reboot in 5 seconds"
	sleep 4
	echo "Rebooting now!"
	sleep 1
	reboot    
}

restore_from_hda3()
{
	clear
	echo " "
	echo "Restoring from Harddrive backup"
	echo "This will take several minutes."
	echo " "
	echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
	sleep 3
	mkdir /hda1
	mkdir /hda3
	mount /dev/hda1 /hda1
	mount /dev/hda3 /hda3
	cd /hda3
	tar -xzf hda1backup.tar.gz -C /
	clear
	echo " "
	echo "Operating System on hda1 is now restored from"
	echo "hda1backup.tar.gz on hda3."
	echo " "
	echo "System will begin reboot in 5 seconds"
	sleep 4
	echo "Rebooting now!"
	sleep 1
	reboot    
}

restore_from_permanent()
{
	clear
	echo " "
	echo "Restoring from permanent backup file "
	echo "located on this disk"
	echo "This will take several minutes."
	echo " "
	echo "-==DO NOT TURN OFF COMPUTER DURING THIS TIME==-"
	sleep 3
	mkdir /hda1
	mount /dev/hda1 /hda1
	cd /KNOPPIX/backup
	tar -xvzf hda1backup.tar.gz -C /
	clear 
	echo " "
	echo "Restoration Complete.  This system will reboot in 5 seconds"
	sleep 4
	echo "Rebooting now!"
	sleep 1
	reboot


restore_mbr()
{
clear
	echo " "
	echo "Restoring Master Boot Record (MBR) from permanent backup file "
	echo "permanent backup file located on this disk"
	sleep 3
#need to do "dd" restoration operations here 
	clear 
	echo " "
	echo "MBR Restoration Complete.  This system will reboot in 5 seconds"
	sleep 4
	echo "Rebooting now!"
	sleep 1
	reboot
}

}
## This is what's seen on the screen when the script begins
clear
echo "  "
echo "Roslin's Restore Disk ver 1.0 "
echo "  "
echo "  "
echo "Choose from one of the options below to begin"
echo "  "
echo "1. Backup Operating System to Harddrive"
echo "2. Restore Operating System from Harddrive"
echo "3. Restore Operating System from This Disk"
echo "4. Restore MBR"
echo " "
echo "       Enter any other number to exit this script "
echo "       and continue booting to DSL Live Session"
echo " "
echo "Enter your choice: "
read choice
case $choice in
    1) backup_to_hda3   
       ;;
    2) restore_from_hda3
       ;;
    3) restore_from_permanent
		 ;;
    4) restore_mbr
		 ;;
    *) exit
esac

Last edited by CyberCod; 03-26-2007 at 08:32 PM.
 
Old 03-26-2007, 11:11 PM   #34
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
I'm keeping the most up to date version of the script on the first post. So if you wish to check it out, look there.
 
Old 03-27-2007, 09:40 PM   #35
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
Some thoughts from a brain-storming session on this project:

Can do backups and restores for Ubuntu installations
Make 4 partitions

hda1 Main Linux OS install 5 GB
hda2 swap 1 GB
hda3 DSLbackup install 3 or 4GB
hda4 storage -remainder of drive mounted at /home


Make dsl hd install on hda3 for backup/restore purposes
Make script to change /hda3/opt/bootlocal.sh from two possible versions
each pointing to different scripts depending on whether it is backup or restore.

Make it happen automatically
make two versions of menu.lst and swap them out then reboot
so that it will boot to the second install.
do backup on 2nd install then, after the backup or restore operations are complete, swap menu.lst back at the end of the script so it will boot to main OS and reboot.

Can also make a permanent DSL based restore DVD with the MainOS restore file on it with the (unfinished) dd backup of the MBR, as was original plan.

Need to learn to use strings in scripting so I can let user choose what partitions/OS to be backed up and what partition/drive to use as storage for the backup file. If I can save these settings to a file and read them on next run of script, then even better.

Can I make the boot process silent with this? > /dev/null 2>&1

Last edited by CyberCod; 03-27-2007 at 09:44 PM.
 
Old 03-27-2007, 10:46 PM   #36
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
Well

If you persist, you may achieve your original goal, (make it easy for a child to re-build). Based on what you have gone through so far, you will be a "Linux Guru" eventually. Just don't lose focus on your original goal.
I have set up similar situations in one evening using bootitng, then hand the computer to the owner with a step by step instruction sheet and a floppy/CD with bootitng. I never "ever" had to coach or interact with the owner ever again. This relates to an a..hole computer with a weak Intel 950Mghz processor and an i810 chip set that had me going over there re-formatting and re-loading every 6 months and spending up to three days doing it with all the re-boots required with Window ME installing all the owners favorite apps.

And the owner never had to pay a cent for bootitng as according to license agreement, if you don't install it permanently, you don't pay dick squat.

Last edited by Junior Hacker; 03-28-2007 at 12:00 AM.
 
Old 03-27-2007, 11:25 PM   #37
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Junior Hacker
Well

If you persist, you may achieve your original goal, (make it easy for a child to re-build). Based on what you have gone through so far, you will be a "Linux Guru" eventually. Just don't loose focus on your original goal.

Thanks for the encouragement.
 
Old 03-29-2007, 03:19 AM   #38
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,605

Rep: Reputation: 53
one thought
you can save partition info (in addition to MBR, I believe it is contained in the fist sector, but...)
with
sfdisk -d or -l /dev/hda > partition.info (see man pages)
and can be restored
with the like of (check syntax)
sfdisk /dev/hda < partition.info
 
Old 03-29-2007, 05:49 AM   #39
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
use that instead of dd?
 
Old 03-29-2007, 08:53 AM   #40
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,605

Rep: Reputation: 53
in addition, sfdisk just give information about where each partition are, and what size
I do not know how much this is redondant with dd of MBR, but at least it is clear information
be paranoid, do both
 
Old 03-29-2007, 07:53 PM   #41
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
I was looking at some of the tutorials on the page you suggested a few posts back, and I was reading about using the "echo" command using the "-n" option.

I was wondering if something could be piped into that.

The tar operation has a LOT of information, I'd like to confine it to just displaying on one line. But I don't want to completely disable its output, in the event of an error.

Would something like this work?
Code:
echo -n (tar -xvzf hda1backup.tar.gz -C /)
Or
Code:
tar -xvzf hda1backup.tar.gz -C / | echo -n
or is it possible at all?

I made an inquiry on the big dd thread by AwesomeMachine, but I've yet to get a reply.

I believe the snippets of code below will work, but I am not wanting to experiment with dd or the MBR until I have confirmation that this is correct usage.

Code:
dd if=/dev/hda of=/hda3/backup/MBR.image bs=446 count=1
This (from what I gather) will back up the MBR of hda to a file called MBR.image, in the /hda3/backup directory...

and to restore the mbr would be the opposite...
which would be

Code:
dd if=/hda3/backup/MBR.image of=/dev/hda bs=466 count=1

Can anyone verify this?

Thanx ahead of time...
 
Old 03-31-2007, 10:34 AM   #42
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
Well,

I believe I'm almost finished.

The way I have it set up now is pretty sweet.

I added two options to the fluxbox menu, one for backup and one for restore.

I installed a second copy of DSL onto hda3 and have scripts there designed to do one or the other.

I've got extra copies of /boot/grub/menu.lst that get swapped out with the scripts that tell it to reboot to the hda3 install, as well as alternate versions of /opt/bootlocal.sh on hda3 that start different scripts depending on what operation is desired.

So in addition to the restore disk, I've got an automated backup/restore system going on without using a disk at all.

The automated system will do its job completely without input from the user after it is started, and when finished, reboot back to the hda1 system.

The restore disk has the ability to restore both systems, on hda1 and hda3.

So using the resident restore system, she can do incremential backups and restores, and using the disk, she can restore from an incremential backup, as well as do a full "factory" restore back to the basic settings.

I'll be posting this all in the DSL forums shortly, and I'll put a link in here for the thread when it is complete.

Thanks to everyone who helped me through this project, especially Emmanuel_uk.

I've learned a lot.

Last edited by CyberCod; 03-31-2007 at 10:36 AM.
 
Old 03-31-2007, 03:32 PM   #44
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,605

Rep: Reputation: 53
Congratulations on putting all that together. You must be a fast learner!
Am glad I could help, thanks for saying thanks. Actually I really appreciate you posted
how you have done all that. This is real open source spirit :-)
and I am sure it will be helpfull to some people. If I come accross threads about old laptop
like yours I will point people to your post

Happy linux to you
 
Old 03-31-2007, 06:11 PM   #45
CyberCod
Member
 
Registered: Jul 2006
Posts: 35

Original Poster
Rep: Reputation: 15
It seems I spoke too soon.

For some reason, the bash scripting in DSL doesn't seem to like those functions. It keeps ignoring them.

Which means that the CD doesn't work as it is currently written.

I was calling it success based on the logic of it, but I'm just now trying it out.

I'm going to investigate and try to find out why it doesn't understand my functions.

I've quadruple checked everything... It may just be an older version of bash. I'll get to the bottom of this!

I ended up having to delete everything in the script except for the restore_from_permanent function and I had to take off the { and } and comment out the function name, just to get it to run.

Also, it didn't work exactly like planned with the dd portion.

I had completely removed the mbr before testing. So of course i needed to put it back.

Well, booting up with no MBR and then restoring it still didn't give me the /dev entries I needed. So a second boot was needed so that the partitions would be there while booting up and hence be represented in /dev.


Go figure.

I'll post again soon.

Last edited by CyberCod; 03-31-2007 at 06:24 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
back up and restore disk partitions ekdya Debian 2 10-05-2006 05:43 PM
Restore vfat disk tripmix Linux - Newbie 1 08-25-2006 08:57 AM
Is a restore disk on Linspire possible? mhucek Linspire/Freespire 1 02-03-2005 06:13 PM
Question about Restore Disk??? Typhonian Linux - General 1 04-18-2003 06:00 AM
disk data restore zeky Linux - General 0 08-05-2002 08:08 AM


All times are GMT -5. The time now is 04:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration