Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
make your own Stage4 mini HOWTO
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3, 4, 5, 6  Next  
This topic is locked: you cannot edit posts or make replies.    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Deranger
Veteran
Veteran


Joined: 26 Aug 2004
Posts: 1215

PostPosted: Sun Sep 26, 2004 10:00 am    Post subject: Reply with quote

Hmm, that sounds pretty neat...Maybe I'll give a try. But I don't see any point for backupping device nodes because I'm using pure UDEV ;)
Back to top
View user's profile Send private message
CRC
Tux's lil' helper
Tux's lil' helper


Joined: 30 Mar 2003
Posts: 90
Location: Dallas, TX, USA

PostPosted: Sun Sep 26, 2004 10:20 am    Post subject: Reply with quote

Pure Udev? Or Gentoo's UDEV?

You do realize that Gentoo does some work there to make udev work, including saving a tarball of devices (which is not possible, traditionally, with tar, but I've yet to scour the INFO pages to see when that feature was added to GNU's version - its certainly not portable).

I've also had some problems where device nodes didn't come back, like /dev/video0 and such. They work fine now under udev, but I think its actually the device tarball that gentoo does that is saving that. Basically, it doesn't hurt to back them up as it only takes up the space of the header, and its a good habit since many systems, like Sun or SCO, would be crippled if /dev got messed up. Also, some linux malware hides itself in /dev.

I also like how cpio tends to be a cleaner interface, fewer flags required.
_________________
Unix/Linux Consulting & Hosting
We Support Gentoo!
http://CoolRunningConcepts.com

Freenode: Taro!
Back to top
View user's profile Send private message
postop
n00b
n00b


Joined: 20 Dec 2003
Posts: 12
Location: Austin, TX

PostPosted: Sun Sep 26, 2004 10:36 am    Post subject: Reply with quote

Oktane wrote:
I don't know about that, but tar-backup works great but you need to exclude things...

I've excluded:

/dev/*
/tmp/*
/var/tmp/*
/usr/portage/distfiles/*
/sys/*
/proc/*
/mnt/*
/data

This Stage 4 is nice, it's like Stage 1 without bootstrapping ;)


Am I doing something wrong with grub then? The wiki says fstab and lilo/grub like it's something really simple.
Back to top
View user's profile Send private message
Deranger
Veteran
Veteran


Joined: 26 Aug 2004
Posts: 1215

PostPosted: Sun Sep 26, 2004 11:18 am    Post subject: Reply with quote

I'm lost...Is this really everything needed to make full backup? How can I speficy things I want exclude? Tarring is much more simplier.

Code:

To backup:
find / | grep -v mybackup.cpio.gz | cpio -o -B | gzip -c >/mybackup.cpio.gz

To restore:
gzip -cd </mybackup.cpio.gz | cpio -i -Bmd
Back to top
View user's profile Send private message
postop
n00b
n00b


Joined: 20 Dec 2003
Posts: 12
Location: Austin, TX

PostPosted: Sun Sep 26, 2004 7:14 pm    Post subject: Re: Copying /dev Reply with quote

CRC wrote:
First, I don't know how you copied /dev, or why anyone would try to tar /dev. Most Unix tools don't deal with /dev or sparse files properly at all! Tar will try doing weird things like putting /dev/hda into the file, which is the entire contents of your hard disk!

Sparse files are created (in C/geek talk, using open, then seek, then write/close) so that the filesystem can store very large files but only store the data you specifically write into the file. So a 2GB file might only be taking up 20MB, even if the file size says its 2GB. Tar will try to back up 2GB, not 20MB.

The solution for both problems is simple. Don't back up (or copy) using tar. The best way to back up weird stuff and preserve EVERYTHING is to use cpio instead. cpio is also a great way to copy whole directories including all subdirectories, permissions, etc (using -p). Check "man cpio". You usually feed it with "find" and then feed the output into gzip.

To backup:
find / | grep -v mybackup.cpio.gz | cpio -o -B | gzip -c >/mybackup.cpio.gz

To restore:
gzip -cd </mybackup.cpio.gz | cpio -i -Bmd

The grep just filters off the file from the list. Cpio uses -i and -o to copy "in" and "out" of the filesystem (to do both, use -p, passthrough). -B uses a larger buffer size (faster). The -m is to preserve file modification time of the original and not use the current time. The -d is to make any directories that it needs.

Have fun.


I took a peek into gentoos stage3.tar.bz2 and there is a full /dev in there. So I'm wondering is the only reason people exclude /dev to make it portable for different machines? So why does gentoo release a stage 3 tar with /dev in it if it's supposed to be portable? Does the x86 stage 3 archive just have a /dev that is supposed to be common to all x86 architectures? Is it safer to exclude /dev and run MAKEDEV instead?

As for how I copied the /dev, I just booted from the live cd, mounted /mnt/gentoo and copied the live cd's /dev into /mnt/gentoo/dev. I figured that if it ran MAKEDEV to build it's /dev dir, then copying it wouldn't be an issue.

I've seen a couple of threads from a google search about tar/cpio comparisons, http://www.delorie.com/gnu/docs/tar/tar_122.html in particular. It seems this debate has been going on for a while. Anyone else like chime in with their pros and cons?[/u]
Back to top
View user's profile Send private message
CRC
Tux's lil' helper
Tux's lil' helper


Joined: 30 Mar 2003
Posts: 90
Location: Dallas, TX, USA

PostPosted: Mon Sep 27, 2004 7:34 am    Post subject: Reply with quote

postop wrote:
I took a peek into gentoos stage3.tar.bz2 and there is a full /dev in there. So I'm wondering is the only reason people exclude /dev to make it portable for different machines? So why does gentoo release a stage 3 tar with /dev in it if it's supposed to be portable? Does the x86 stage 3 archive just have a /dev that is supposed to be common to all x86 architectures? Is it safer to exclude /dev and run MAKEDEV instead?


Yeah, Admins are creatures of habit. First time tar gave me issues with /dev, I quit using it for any sort of large system backups and started using cpio. I've done complete installs from gzipped cpio achives over a network! GNU Tar under Linux shouldn't be an issue, but if you have problems, use cpio! What would you be using instead of GNU Tar? Hmm other than many Solaris, Irix, probably AIX, etc, and ... how often have you been using some boot CD, alterative install method, embedded system or whatever, that is using busybox? I don't know if busybox can handle special files or not. Maybe it can. I know cpio does. Pick whichever one works best for you really, I just wanted to get another option out there, which happens to be my personal preference.

As for MAKEDEV, You would use MAKEDEV on Linux up to 2.4. For most 2.4 systems you should probably migrate to devfs (although the tarball or cpio-ball helps when devfs doesn't restore permissions just right). For 2.6, the push is to move to udev. The benefits of udev won't be immediately noticeable until the desktops catch up.

postop wrote:
As for how I copied the /dev, I just booted from the live cd, mounted /mnt/gentoo and copied the live cd's /dev into /mnt/gentoo/dev. I figured that if it ran MAKEDEV to build it's /dev dir, then copying it wouldn't be an issue.


Now I feel old. In the old days, trying to do a recursive copy of /dev would hang the system and bork up all kinds of stuff. The solution was simple. DON'T DO THAT. And I haven't done it many years. Looks like even 'cp' will do the right thing now. No wonder the GNU tools are so getting so big. Nice to know, but next time I take a snapshot of /dev files, I doubt I'll use "cp" over "cpio" ... habit. I trust cpio.

postop wrote:
I've seen a couple of threads from a google search about tar/cpio comparisons, http://www.delorie.com/gnu/docs/tar/tar_122.html in particular. It seems this debate has been going on for a while. Anyone else like chime in with their pros and cons?


Well, the author seemed biased towards tar. I've never had problems with cpio not recognizing hard links due to the limited inode number size. Perhaps much larger filesystems would be an issue. The comparison on that site didn't mention sparse files at all. There are goods and bads for each approach, I personally prefer to feed a file list from stdin vs wildcards and "excluding".

Anyone that wants to do real backups should look into a dedicated backup program. tar and cpio are fine to backup to floppy or CD or even DVD for personal use, but if you have a business running off that data, you might want to look into another method. For open-source, try Amanda. You might also want to look into using LVM2 so you can grow/shrink partitions easier and make use of "snapshots" to make backups easier. FYI, while most source code is downloaded in tar format, most RPMs are a header around a cpio archive.

As for grub/lilo, lilo is just a pain to back up since you have to reinstall it every time the position of a file on disk changes. For grub, you can save a copy of your partition table which should have the boot record too. Something like

Code:
dd if=/dev/hda of=/dev/boot.img bs=512 count=1

to save it, and then
Code:
dd if=/dev/boot.img of=/dev/hda bs=512 count=1

should restore it.

I haven't tested this in awhile, so please don't test this on something you can't fix. And "gpart" is your friend if you bork your partition table. You can NOT use this boot.img on any other drive or partitioning scheme other than the one it was saved on. You will end up reinstalling everything (or running gpart off a boot disk like LNX-BBC and praying).

Another way to do a "stage 4" might be to just turn on "buildpackages" in FEATURES (I think thats the right string), or always use the "-b" flag to emerge. You can then install these again with emerge -k. Still doesn't help with grub/lilo, but thats a part of disaster recovery and is the job of the backup system to do for you. Most good restore programs can boot the system restore the backup and reinstall everything. Also check out this info:
http://www.backupcentral.com/toc-free-backup-software.html
_________________
Unix/Linux Consulting & Hosting
We Support Gentoo!
http://CoolRunningConcepts.com

Freenode: Taro!
Back to top
View user's profile Send private message
Gavrila
Apprentice
Apprentice


Joined: 08 Jun 2003
Posts: 275

PostPosted: Mon Oct 18, 2004 7:34 am    Post subject: Reply with quote

I've found to be able to use --exclude options only if put BEFORE the starting directory from where to start tarring

e.g.: tar cjpf /path/to/backup.tar.bz2 / --exclude=/foo

won't exclude /foo pattern matching files

while:

tar --exclude=/foo cjpf /path/to/backup.tar.bz2 /

will do its dirty work. I think you should update you're wiki how-to.

Kind Regards
Back to top
View user's profile Send private message
tscolari
l33t
l33t


Joined: 02 May 2004
Posts: 602
Location: curitiba - pr - Brazil

PostPosted: Tue Oct 19, 2004 10:18 pm    Post subject: Reply with quote

Just a question

I would like to prepare a stage4 for a computer at my work.
But here i use a athlon xp and there it is a pentium 233mhz... How can I (is it possible?) make my althlon compile all for a pentium? or i will have a lot of problems?
_________________
------------------------------------
Tiago Scolari
Back to top
View user's profile Send private message
Gavrila
Apprentice
Apprentice


Joined: 08 Jun 2003
Posts: 275

PostPosted: Tue Oct 19, 2004 10:30 pm    Post subject: Reply with quote

tscolari wrote:
Just a question

I would like to prepare a stage4 for a computer at my work.
But here i use a athlon xp and there it is a pentium 233mhz... How can I (is it possible?) make my althlon compile all for a pentium? or i will have a lot of problems?


u can choose or -mtune=athlon-xp which will try to optimize for the amd but will keep compatibility for any other x86.
Otherwise u could try -march=i686 (is it ? o i586 for that pentium?) which will be compatible with both.
As last option u can compile with -march=pentium2 (or whatever it is), but u won't be able to use it on ur amd machine.

regards
_________________
Jabber ID: Gavrila@jabber.org
Back to top
View user's profile Send private message
CRC
Tux's lil' helper
Tux's lil' helper


Joined: 30 Mar 2003
Posts: 90
Location: Dallas, TX, USA

PostPosted: Wed Oct 20, 2004 9:08 pm    Post subject: Reply with quote

Gavrila wrote:
tscolari wrote:
Just a question

I would like to prepare a stage4 for a computer at my work.
But here i use a athlon xp and there it is a pentium 233mhz... How can I (is it possible?) make my althlon compile all for a pentium? or i will have a lot of problems?


u can choose or -mtune=athlon-xp which will try to optimize for the amd but will keep compatibility for any other x86.
Otherwise u could try -march=i686 (is it ? o i586 for that pentium?) which will be compatible with both.
As last option u can compile with -march=pentium2 (or whatever it is), but u won't be able to use it on ur amd machine.

regards


Ah, well, the Athlon can and does run Pentium and Pentium2 code, and any pentium3 code that doesn't use sse instructions.

Your pentium is a pentium, 586, not 686, so you want to compile for 586 being the minimum architecture but tune for 686 (never tune for pentium unless you will never run the code on anything faster). Tuning for 686 doesn't really hurt pentium speed, but vice-versa is true.

As for AMDs, K5 is 486, K6 is 586/pentium, K6/2 is K6 with MMX (and 3dnow), K6/3 is K6/2 with Mobile/PowerNow.

The Pentium MMX was Intel's new chip at the time for desktops, while the Pentium Pro was for servers. The Pentium Pro was the 686.

The Pentium2 (686) is the Pentium Pro with MMX enhancements. The Pentium 3 is just a Pentium 2 with the SSE instructions added (to compete with 3dnow).

The Pentium 4 is a complete redesign that is tuned for media instructions, and actually runs typical integer/business type instructions SLOWER than a pentium3 at the same clock speed (for multiple reasons). Its claim to fame is purely the high clock rates.

The Athlon has improved 3dnow, plus a screaming fast floating point and integer unit.

If you optimize for Athlon or Pentium4, throw compatibility out the window. Most Athlons are variations of K7, and there are quite a few of them and they are all a bit different to optimize for. The K8s and AMD 64s are new animals too. Seems Intels latest generations aren't getting very far. Oh, and when you see Celeron, its just the "cheaper" version of the same chip (like the old SX designation), and Xeon is a larger cached Server version.
_________________
Unix/Linux Consulting & Hosting
We Support Gentoo!
http://CoolRunningConcepts.com

Freenode: Taro!
Back to top
View user's profile Send private message
seppe
Guru
Guru


Joined: 01 Sep 2003
Posts: 431
Location: Hove, Antwerp, Belgium

PostPosted: Fri Oct 22, 2004 1:50 pm    Post subject: Reply with quote

I backed up with this command:
Code:

tar cjpf /20041022-stage4-Helios.tar.bz2 / --exclude=20041022-stage4-Helios.tar.bz2 --exclude=proc/* --exclude=dev/* --exclude=sys/* --exclude=tmp/* --exclude=stage4-errors.log 2>stage4-errors.log


I'm going to write it to a DVD, I hope I can restore my system when it breaks someday
_________________
nitro-sources, because between stable and experimental there exists only speed

Latest release I made: 2.6.13.2-nitro1
Back to top
View user's profile Send private message
seppe
Guru
Guru


Joined: 01 Sep 2003
Posts: 431
Location: Hove, Antwerp, Belgium

PostPosted: Fri Oct 22, 2004 2:23 pm    Post subject: Reply with quote

hmm, it's still busy but I fired up cat stage4-errors.log already, and it showed this:
Code:

tar: Removing leading `/' from member names
tar: Removing leading `/' from hard link targets
tar: /dev/log: socket ignored
tar: /proc/acpi/event: Cannot open: Device or resource busy
tar: /proc/2/task/2/exe: Cannot readlink: No such file or directory
tar: /proc/2/exe: Cannot readlink: No such file or directory
tar: /proc/3/task/3/exe: Cannot readlink: No such file or directory
tar: /proc/3/exe: Cannot readlink: No such file or directory
tar: /proc/4/task/4/exe: Cannot readlink: No such file or directory
tar: /proc/4/exe: Cannot readlink: No such file or directory
tar: /proc/5/task/5/exe: Cannot readlink: No such file or directory
tar: /proc/5/exe: Cannot readlink: No such file or directory
tar: /proc/6/task/6/exe: Cannot readlink: No such file or directory
tar: /proc/6/exe: Cannot readlink: No such file or directory
tar: /proc/27/task/27/exe: Cannot readlink: No such file or directory
tar: /proc/27/exe: Cannot readlink: No such file or directory
tar: /proc/28/task/28/exe: Cannot readlink: No such file or directory
tar: /proc/28/exe: Cannot readlink: No such file or directory
tar: /proc/39/task/39/exe: Cannot readlink: No such file or directory
tar: /proc/39/exe: Cannot readlink: No such file or directory
tar: /proc/40/task/40/exe: Cannot readlink: No such file or directory
tar: /proc/40/exe: Cannot readlink: No such file or directory
tar: /proc/42/task/42/exe: Cannot readlink: No such file or directory
tar: /proc/42/exe: Cannot readlink: No such file or directory
tar: /proc/41/task/41/exe: Cannot readlink: No such file or directory
tar: /proc/41/exe: Cannot readlink: No such file or directory
tar: /proc/577/task/577/exe: Cannot readlink: No such file or directory
tar: /proc/577/exe: Cannot readlink: No such file or directory
tar: /proc/599/task/599/exe: Cannot readlink: No such file or directory
tar: /proc/599/exe: Cannot readlink: No such file or directory
tar: /proc/606/task/606/exe: Cannot readlink: No such file or directory
tar: /proc/606/exe: Cannot readlink: No such file or directory
tar: /proc/607/task/607/exe: Cannot readlink: No such file or directory
tar: /proc/607/exe: Cannot readlink: No such file or directory
tar: /proc/608/task/608/exe: Cannot readlink: No such file or directory
tar: /proc/608/exe: Cannot readlink: No such file or directory
tar: /proc/8754/task/8754/exe: Cannot readlink: No such file or directory
tar: /proc/8754/exe: Cannot readlink: No such file or directory
tar: /proc/10020/task/10020/fd/3: Cannot stat: No such file or directory
tar: /proc/10020/fd/3: Cannot stat: No such file or directory


How can that be? I excluded /proc and /dev, why do I get errors on it then? Could it be that --exclude doesn't handle sub directories or something? Anyone know what's wrong here, and should I stop the tarring and restart with another command? Or isn't this a problem when I extract my stage4 in the future?
_________________
nitro-sources, because between stable and experimental there exists only speed

Latest release I made: 2.6.13.2-nitro1
Back to top
View user's profile Send private message
Deranger
Veteran
Veteran


Joined: 26 Aug 2004
Posts: 1215

PostPosted: Fri Oct 22, 2004 2:26 pm    Post subject: Reply with quote

Seppe, you have
Code:

--exclude=proc/*

It should be
Code:

--exclude=/proc/*

And so on...

If you don't need/want any downloaded sources to be included, exclude /usr/portage/distfiles/*


Last edited by Deranger on Fri Oct 22, 2004 2:30 pm; edited 1 time in total
Back to top
View user's profile Send private message
seppe
Guru
Guru


Joined: 01 Sep 2003
Posts: 431
Location: Hove, Antwerp, Belgium

PostPosted: Fri Oct 22, 2004 2:30 pm    Post subject: Reply with quote

Oktane wrote:
Seppe, you have
Code:

--exclude=proc/*

It should be
Code:

--exclude=/proc/*

And so on...


I tried that first, and I think I would have the same output. I got tar: /proc/acpi/event: Cannot open: Device or resource busy then as well, but I quit it to try it without leading / because tar said
Quote:

tar: Removing leading `/' from member names


Besides, I run this command from /, so it doesn't matter, I think?
_________________
nitro-sources, because between stable and experimental there exists only speed

Latest release I made: 2.6.13.2-nitro1


Last edited by seppe on Fri Oct 22, 2004 2:32 pm; edited 1 time in total
Back to top
View user's profile Send private message
Deranger
Veteran
Veteran


Joined: 26 Aug 2004
Posts: 1215

PostPosted: Fri Oct 22, 2004 2:32 pm    Post subject: Reply with quote

I'm not sure, but add / in front of them, try to tar your system again and see if there's same errors.
Back to top
View user's profile Send private message
seppe
Guru
Guru


Joined: 01 Sep 2003
Posts: 431
Location: Hove, Antwerp, Belgium

PostPosted: Fri Oct 22, 2004 3:39 pm    Post subject: Reply with quote

Hmm I don't get it, I tried it again with this command:
Code:

tar cjpf /20041022-stage4-Helios.tar.bz2 / --exclude=/20041022-stage4-Helios.tar.bz2 --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/tmp --exclude=/stage4-errors.log 2>stage4-errors.log


And I still get the same errors on /proc and /dev, which should be excluded 8O
_________________
nitro-sources, because between stable and experimental there exists only speed

Latest release I made: 2.6.13.2-nitro1
Back to top
View user's profile Send private message
gungholady
Guru
Guru


Joined: 19 Oct 2003
Posts: 392

PostPosted: Fri Oct 22, 2004 9:51 pm    Post subject: Reply with quote

seppe wrote:
Hmm I don't get it, I tried it again with this command:
Code:

tar cjpf /20041022-stage4-Helios.tar.bz2 / --exclude=/20041022-stage4-Helios.tar.bz2 --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/tmp --exclude=/stage4-errors.log 2>stage4-errors.log


And I still get the same errors on /proc and /dev, which should be excluded 8O


I used the script from gentoo-wiki which I modified just slightly for what I want and it works just fine.
Back to top
View user's profile Send private message
CRC
Tux's lil' helper
Tux's lil' helper


Joined: 30 Mar 2003
Posts: 90
Location: Dallas, TX, USA

PostPosted: Sun Oct 24, 2004 7:58 am    Post subject: Reply with quote

What no one has mentioned yet is how to use a "stage4" and use it with a network boot image, such as a pxeboot or grub (grub can optionally be compiled with network drivers to boot kernels over the network, so you can use it as a boot floppy).

If you've ever seen a large datacenter do installs do 500 machines, you'd know they don't pop a CD into each one and manually install the system. That would be insane. Gentoo would be much more acceptable for servers if there was more automated support for creating a "stage4" with apache and friends and then blowing onto as many servers as you want.

Anyone want to write a how-to?
_________________
Unix/Linux Consulting & Hosting
We Support Gentoo!
http://CoolRunningConcepts.com

Freenode: Taro!
Back to top
View user's profile Send private message
BlinkEye
Veteran
Veteran


Joined: 21 Oct 2003
Posts: 1046
Location: Gentoo Forums

PostPosted: Thu Nov 11, 2004 3:19 pm    Post subject: Reply with quote

please continue here if you're interested in my script. i won't update this version anymore.

INDEX
    0. What's this all about
    1. How it works
    2. How to customise
    3. The results
    4. The script
    5. What now
    6. Warnings

0. What's this all about
i want to backup my system easily with minimum effort. that's why i wrote this script. the resulting backup file (.tar.bz2) is called a stage4. you're probably a gentoo user and hence know the three stages gentoo uses. this backup will be a stage4 meaning it will be a full system backup of your current system.

1. How it works
it's a bash script which uses only "standard" tools, namely "tar", "bzip2" and if you intend to burn the stage4 on a cd you'll probably use "split" too. this means this script works out of the box. it has been modified a lot and i now tried to detect any error/misconfiguration a user might do (wrong $PATH, wrong commands, wrong exclude list, overwriting existing files ...).
after checking everything's all set up the script will provide you with two options:
Code:

Backup script v1.1
===================

What do you want to do? (Use CONTROL-C to abort)

(1) Minimal backup
(2) Interactive backup

Please enter your option:

the minimal backup allows you to quickly build a stage4.tar.bz2 without any further fuss, which means
1. it will exclude (i.e. NOT backup) any files/directories listed in the $exclude_custom_list variable
2. result in a minimal stage4
the interactive backup will ask you for any file/directory listed in the $exclude_custom_list variable if you want it to backup. this might result in the same stage4.tar.bz2 if you answer all question with "no" or in a considerably bigger stage4.tar.bz2. the idea of the $exclude_default_list is to put any file/directory in there which is never needed for a minimal full system backup. files/directories listed in $exclude_custom_list are directories which aren't needed either but which may be desirable to be backup-ed too (like /home or /usr/src/). of course opinions about such files/directories differ, so suit yourself.

2. How to customise
as mentioned above there are several variables to customise. the script itself has a few comments which should get you started. you might want to change the location where the stage4.tar.bz2 is put (currently /mnt/backups/stage4), or you might not like the filename (hostname-stage4-datum.tar.bz2), or you might think that the kernel sources is part of a minimal system backup and hence you won't exclude it (and so on) ...

3. The results
the result is IMPRESSIVE. you'll get a stage4.tar.bz2 (for me it's about 800MB from 3.5GB of data) which will be a fully working backup of your system. on my ibm laptop (x40 - with a damn slow harddisk) - it takes about 50 minutes to create the stage4. i recall all those hours i backup-ed my windows installation. the record was 7CD's for a full installation (inkl. all the software you need for the daily use).


4. The Script
Code:
#!/bin/bash
# Backup script for Gentoo Linux
# Author: Reto Glauser aka Blinkeye
# Mailto: stage4 at blinkeye dot ch
# Date: 23.03.2005

version=v1.2

# these are the commands we actually need for the backup
command_list="echo tar hostname date split"

# verify that each command we use exists
for command in $command_list; do
 path=`which $command | grep "no $command in"`
 
 if [ ! -x `which $command` -a "$path" ]; then
  echo -e "\n\nERROR: $command not found! Check your commands and/or your \$PATH"
  exit -1
 fi
done

# options for the tar command
tarOptions="--create --absolute-names --preserve-permissions --totals --bzip2 --ignore-failed-read --verbose --file"

# where to put the stage4
stage4Location=/mnt/backups/stage4

# name prefix
stage4prefix=$(hostname)-stage4-`date +\%d.\%m.\%Y`

# these files/directories are always excluded
default_exclude_list="
--exclude=/tmp/*
--exclude=/var/tmp/*
--exclude=/lost+found/*
--exclude=/dev/*
--exclude=/proc/*
--exclude=/mnt/*
--exclude=/sys/*
--exclude=/usr/portage/*
--exclude=/var/log/*
--exclude=$stage4Location"

# depending on your choice these files or directories will additionally be excluded
custom_exclude_list="
--exclude=/usr/src/*
--exclude=/opt/mathematica
--exclude=/usr/share/smssend
--exclude=/home/*"

# check the folder/files stored in $default_exclude_list exist
for exclude in $default_exclude_list; do
   if [ ! -e "`echo "$exclude" | cut -d'=' -f2 | cut -d'*' -f1`"  ]; then
      echo -e "\n\nERROR: `echo "$exclude" | cut -d'=' -f2` not found! Check your \$default_exclude_list"
   fi
done

# check the folder/files stored in $custom_exclude_list exist
for exclude in $custom_exclude_list; do
   if [ ! -e "`echo "$exclude" | cut -d'=' -f2 | cut -d'*' -f1`"  ]; then
      echo -e "\n\nERROR: `echo "$exclude" | cut -d'=' -f2` not found! Check your \$custom_exclude_list"
   fi
done

# print out the version
 echo -e "\nBackup script $version"
 echo -e "==================="


# how do you want to backup?
echo -e "\nWhat do you want to do? (Use CONTROL-C to abort)\n
(1) Minimal backup
(2) Interactive backup"

while [ "$option" != '1' -a "$option" != '2'  ]; do
   echo -en "\nPlease enter your option: "
   read option
done

case $option in
1)
   stage4Name=$stage4Location/$stage4prefix-minimal
   final_command="tar $default_exclude_list $custom_exclude_list $tarOptions $stage4Name.tar.bz2 / /var/log/emerge.log"
   ;;
2)
   for folder in $custom_exclude_list; do
      echo -en "Do you want to backup" `echo "$folder" | cut -d'=' -f2`"? (y/n) "
      read answer
      while [ "$answer" != 'y' -a "$answer" != 'n' ]; do
         echo "please enter y or n"
         read answer
      done
      if [ "$answer" == 'n' ]; then
         default_exclude_list="$default_exclude_list $folder"
      fi
   done
   
   stage4Name=$stage4Location/$stage4prefix-custom
   final_command="tar $default_exclude_list $tarOptions $stage4Name.tar.bz2 /  /var/log/emerge.log"
   ;;
esac

# show what will be done
echo -e "\n* creating the stage4 at $stage4Location with the following options:\n\n"$final_command

# everything is set, are you sure to continue?
echo -ne "\nDo you want to continue? (y/n) "
read answer
while [ "$answer" != 'y' ] && [ "$answer" != 'n' ]; do
         echo "please enter y or n"
         read answer
done

if [ "$answer" == 'y' ]; then
   # mount boot
   echo -e "\n* mount boot"
   mount /boot >/dev/null 2>&1   
   
   # if necessary, create the stage4Location
   if [ ! -d "$stage4Location" ] ; then
      echo "* creating directory $stage4Location"
      mkdir -p $stage4Location
   fi
   
   # check whether the file already exists
   if [ -a "$stage4Name.tar.bz2" ]; then 
      echo -en "\nDo you want to overwrite $stage4Name.tar.bz2? (y/n) "
      read answer
      while [ "$answer" != 'y' ] && [ "$answer" != 'n' ]; do
         echo "please enter y or n"
         read answer
      done
      if [ "$answer" == 'n' ]; then
         echo -e "\n* There's nothing to do ... Exiting"
         exit 0;
      fi
   fi
   
   # do the backup
   time $final_command

   # copy the current world file to the stage4 location
   echo -e "\n* creating stage4 overview $stage4Name.txt"
   cp /var/lib/portage/world $stage4Name.txt >/dev/null 2>&1
   
   # we finished, clean up
   echo "* stage4 is done"
   echo "* umounting boot"
   umount /boot
else
   echo -e "\n* There's nothing to do ... Exiting"
fi

#Uncomment the following command if you want to split the archive in cd size chunks:
#split --suffix-length=1 --bytes=670m $stage4Name.tar.bz2 "$stage4Name"_ && echo "* splitting is done"


5. What now
you now have a stage4.tar.bz2. if in need (or if you use this stage4 for another box)
1. untar it
Code:
 tar xvjpf X40-stage4-06.03.2005-minimal.tar.bz2

2. rebuild the portage tree
Code:
emerge sync

3. if necessary install a bootloader, adjust the bootloader and your /etc/fstab

6. Warning
although it's not a disaster it's still anoying. if you have a symlink in /boot
Code:
# ls -l /boot
total 2588
lrwxr-xr-x  1 root root       1 Jul  7  2004 boot -> .

backing up /boot will result in a recursive backing up of boot. this is wasting space and time. the solution is easy, remove the symlink:
Code:
rm /boot/boot

DANGER: if you haven't configured your bootloader correctly (namely grub), you might not be able to boot your kernel. this results of a wrong configuration, which of course is easily solved. if you don't have a seperate /boot partition (check your fstab) your kernel line should look similar to this one:
Code:
...
kernel (hd0,0)/boot/linux-2.6.11-ck1/bzImage root=/dev/hda3

if you use a seperate boot partition remove "/boot"
Code:
...
kernel (hd0,0)/linux-2.6.11-ck1/bzImage root=/dev/hda3


[EDIT]2005-03-06 Completely rewrote the old script[/EDIT]
[EDIT]2005-03-25 Adjusted the split command [/EDIT]
_________________
Easily backup up your system? klick
Get rid of SSH Brute Force Attempts / Script Kiddies klick


Last edited by BlinkEye on Wed Mar 23, 2005 10:23 am; edited 37 times in total
Back to top
View user's profile Send private message
tkdfighter
Apprentice
Apprentice


Joined: 14 May 2004
Posts: 271
Location: Bludenz, Austria

PostPosted: Thu Nov 11, 2004 4:51 pm    Post subject: Reply with quote

BlinkEye, that script of yours looks really good. I'm going to try it out this evening. :D
Back to top
View user's profile Send private message
M@rijn
Tux's lil' helper
Tux's lil' helper


Joined: 28 Jan 2004
Posts: 145
Location: Zierikzee (The Netherlands)

PostPosted: Thu Dec 09, 2004 6:38 pm    Post subject: Reply with quote

Can i just exclude the /sys directory?? and don't backup this dir? Because i have errors on reiser4 with tarring the /sys directory.
_________________
Gentoo is just an Aston Martin, "Power, beauty and soul"
Back to top
View user's profile Send private message
BlinkEye
Veteran
Veteran


Joined: 21 Oct 2003
Posts: 1046
Location: Gentoo Forums

PostPosted: Thu Dec 09, 2004 6:45 pm    Post subject: Reply with quote

yes, but do it like that: --exclude=/sys/* (btw: peek at my script, i do it too)
_________________
Easily backup up your system? klick
Get rid of SSH Brute Force Attempts / Script Kiddies klick
Back to top
View user's profile Send private message
M@rijn
Tux's lil' helper
Tux's lil' helper


Joined: 28 Jan 2004
Posts: 145
Location: Zierikzee (The Netherlands)

PostPosted: Thu Dec 09, 2004 6:50 pm    Post subject: Reply with quote

BlinkEye wrote:
yes, but do it like that: --exclude=/sys/* (btw: peek at my script, i do it too)


Oh damned i see it, your script makes an kind of image of the system, i was making also a script like that :) I think i use yours, so i don't have to test it :)
_________________
Gentoo is just an Aston Martin, "Power, beauty and soul"
Back to top
View user's profile Send private message
seppe
Guru
Guru


Joined: 01 Sep 2003
Posts: 431
Location: Hove, Antwerp, Belgium

PostPosted: Fri Dec 10, 2004 7:56 pm    Post subject: Reply with quote

Hi

I created a stage4 once, and today .. my reiser4 system crashed.
So I restored from my stage4 snapshot, and everything seems to work, except I don't see my runscripts loaded anymore (like "loading sshd [OK]"), but they load in the background because my services all work without any problems. I just don't SEE them loaded.

Also, I get "Warning: could not open an initial console"
and
"Adding xxxxxxxk swap to /dev/hda3. Initial:-1 extents:1"

Does anyone know how I can fix this?

Apart from this, everything works without problems
_________________
nitro-sources, because between stable and experimental there exists only speed

Latest release I made: 2.6.13.2-nitro1
Back to top
View user's profile Send private message
BlinkEye
Veteran
Veteran


Joined: 21 Oct 2003
Posts: 1046
Location: Gentoo Forums

PostPosted: Fri Dec 10, 2004 8:09 pm    Post subject: Reply with quote

sounds very familiar. had that one too with reiser4. check the forums - there are some topics around dealing with that issue. i think you need to create some nodes/devices ...

[EDIT] klick me and/or me may help
_________________
Easily backup up your system? klick
Get rid of SSH Brute Force Attempts / Script Kiddies klick
Back to top
View user's profile Send private message
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies.    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 4 of 6

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum