Sophie

Sophie

distrib > * > 2010.0 > * > by-pkgid > a412ceb851151854794ced2a242192bb > files > 1978

howto-html-fr-20080722-1mdv2010.0.noarch.rpm

<html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>11.&nbsp;Les scripts</title><link href="style.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.67.2" name="generator"><link rel="start" href="index.html" title="
    Guide pratique de sauvegarde et de r&eacute;cup&eacute;ration sous Linux
"><link rel="up" href="index.html" title="
    Guide pratique de sauvegarde et de r&eacute;cup&eacute;ration sous Linux
"><link rel="prev" href="ar01s10.html" title="10.&nbsp;Et maintenant&nbsp;?"><link rel="next" href="ar01s12.html" title="12.&nbsp;Ressources"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">11.&nbsp;Les scripts</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="ar01s10.html">Pr&eacute;c&eacute;dent</a>&nbsp;</td><th align="center" width="60%">&nbsp;</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="ar01s12.html">Suivant</a></td></tr></table><hr></div><div class="sect1" lang="fr"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="TheScripts"></a>11.&nbsp;Les scripts</h2></div></div></div><p>
Reportez-vous aux notes situ&eacute;es au d&eacute;but de chaque script pour voir le r&eacute;sum&eacute; de
ce qu'il fait.</p><div class="sect2" lang="fr"><div class="titlepage"><div><div><h3 class="title"><a name="FirstStage"></a>11.1.&nbsp;Premi&egrave;re &eacute;tape</h3></div></div></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="make.fdisk"></a>11.1.1.&nbsp;<code class="filename">make.fdisk</code></h4></div></div></div><p>

    Ce script, lanc&eacute; pendant la sauvegarde, cr&eacute;e des scripts semblables 
    &agrave; <a href="ar01s11.html#make.dev.hda" title="11.1.2.&nbsp;make.dev.hda"><code class="filename">make.dev.hda</code></a> et 
    <a href="ar01s11.html#mount.dev.hda" title="11.1.3.&nbsp;mount.dev.hda"><code class="filename">mount.dev.x</code></a>, 
    plus bas, pour que vous les lanciez &agrave; la restauration. Il produit 
    aussi des fichiers de donn&eacute;es semblables &agrave; <a href="ar01s11.html#dev.hda" title="11.1.4.&nbsp;dev.hda"><code class="filename">dev.hda</code></a>, plus bas. Le 
    nom du script et du fichier de donn&eacute;es qui est produit d&eacute;pend du 
    p&eacute;riph&eacute;rique donn&eacute; en param&egrave;tre &agrave; ce script. Ce script, lanc&eacute; &agrave; la 
    restauration, cr&eacute;e les partitions sur le disque dur. 
    <code class="filename">make.fdisk</code> est appel&eacute; par <a href="ar01s11.html#save.metadata" title="11.1.5.&nbsp;save.metadata"><code class="filename">save.metadata</code></a>, 
    plus bas.
    
</p><pre class="programlisting">
#! /usr/bin/perl

# A perl script to create a script and input file for fdisk to
# re-create the partitions on the hard disk, and format the Linux and
# Linux swap partitions. The first parameter is the fully qualified
# path of the device of the hard disk, e.g. /dev/hda. The two
# resulting files are the script make.dev.x and the data file dev.x
# (where x is the hard drive described, e.g. hda, sdc). make.dev.x is
# run at restore time to rebuild hard drive x, prior to running
# restore.metadata. dev.x is the input file for fdisk.

# Time-stamp: &lt;2004-04-10 13:51:37 root make.fdisk&gt;

# Copyright 2001 through the last date of modification Charles Curley
# except for the subroutine cut2fmt.

# cut2fmt Copyright (c) 1998 Tom Christiansen, Nathan Torkington and
# O'Reilly &amp; Associates, Inc.  Permission is granted to use this code
# freely EXCEPT for book publication.  You may use this code for book
# publication only with the explicit permission of O'Reilly &amp;
# Associates, Inc.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# In addition, as a special exception, Tom Christiansen, Nathan
# Torkington and O'Reilly &amp; Associates, Inc.  give permission to use
# the code of this program with the subroutine cut2fmt (or with
# modified versions of the subroutine cut2fmt that use the same
# license as the subroutine cut2fmt), and distribute linked
# combinations including the two.  You must obey the GNU General
# Public License in all respects for all of the code used other than
# the subroutine cut2fmt.  If you modify this file, you may extend
# this exception to your version of the file, but you are not
# obligated to do so.  If you do not wish to do so, delete this
# exception statement and the subroutine cut2fmt from your version.

# You can also contact the Free Software Foundation at
# http://www.fsf.org/

# Changes:

# 2004 04 10: fdisk v &gt; 2.11 has wider columns. Added code to select
# the appropriate cut string based on fdisk's version.

# 2004 04 09: Added support for Mandrake's idea of devfs. On Mandrake,
# everything is mounted with devfs. So the mount devices are buried
# deep in places like /dev/ide/host0/bus0/target0/lun0/part1 instead
# of places like /dev/hda1, where $DEITY intended they should be. We
# have to reverse from the long devfs device to the shorter old style
# that tomsrtbt uses. The alternative is to keep track in an array of
# which devfs device belongs to which short device.

# 2003 12 29: Changed the regex for detecting whether a file system is
# read-write in the code that builds the mount file(s). The old test
# does not work if mount returns multiple parameters in the 5th field,
# e.g. (rw,errors=remount-ro) on some debian systems. This regex
# assumes that the rw parameter is always listed first, which may not
# always be the case. If it fails, take out the '\('. Thanks to Pasi
# Oja-Nisula &lt;pon at iki dot fi&gt; for pointing this out.

# 2003 01 09: Added support for FAT32. We now create two scripts for
# each hard drive, make.dev.[as]dx and mount.dev.[as]dx. These create
# and make file systems on each partition, and make mount points and
# mount them.

# 2002 12 25: added support to handle W95 extended (LBA) (f) and W95
# FAT 32 partitions. I have tested this for primary but not logical
# partitions.

# 2002 09 08: Added minimal support for ext3fs. We now detect mounted
# ext3fs partitions &amp; rebuild but with no options. The detection
# depends on the command line "dumpe2fs &lt;device&gt; 2&gt;/dev/null | grep -i
# journal" producing no output for an ext2fs, and output (we don't
# care what) for an ext3fs.

# This could stand extension to support non-default ext3 options such
# as the type of journaling. Volunteers?

# 2002 07 25: Bad block checking is now a command line option (-c) at
# the time the product script is run.

# 2002 07 03: Corrected the mechanism for specifying the default
# drive.

# 2001 11 25: Changed the way mke2fs gets its bad block
# list. badblocks does not guess at the block size, so you have to get
# it (from dumpe2fs) and feed it to badblocks. It is simpler to just
# have mke2fs call badblocks, but you do loose the ability to have a
# writing test easily. -- C^2

# 2001 11 25: Changed the regex that extracts partition labels from
# the mount command. This change does not affect the results at all,
# it just makes it possible to use Emacs' perl mode to indent
# correctly. I just escaped the left bracket in the regex. -- C^2

# Discussion:

# fdisk will spit out a file of the form below if you run it as "fdisk
# -l".

# root@tester ~/bin $ fdisk -l /dev/hda

# Disk /dev/hda: 64 heads, 63 sectors, 1023 cylinders
# Units = cylinders of 4032 * 512 bytes

#    Device Boot    Start       End    Blocks   Id  System
# /dev/hda1             1         9     18112+  83  Linux
# /dev/hda2            10      1023   2044224    5  Extended
# /dev/hda5            10       368    723712+  83  Linux
# /dev/hda6           369       727    723712+  83  Linux
# /dev/hda7           728       858    264064+  83  Linux
# /dev/hda8           859       989    264064+  83  Linux
# /dev/hda9           990      1022     66496+  82  Linux swap

# What fdisk does not do is provide output suitable for later
# importing into fdisk, a la sfdisk. This script parses the output
# from fdisk and creates an input file for fdisk. Use the input file
# like so:

# fdisk /dev/hdx &lt; dev.hdx

# For the bare metal restore package, this script also builds a script
# that will execute the above command so you can run it from your zip
# disk. Because the bare metal restore scripts all are in /root/bin,
# the data file and script created by this script are also placed
# there. The same script also creates appropriate Linux file systems,
# either ext2fs, or Linux swap. There is limited support for FAT12,
# FAT16 and FAT32. For anything else, you're on your own.

# Note for FAT32: According to the MS KB, there are more than one
# reserved sectors for FAT32, usually 32, but it can vary. Do a search
# in M$'s KB for "boot sector" or BPB for the gory details. For more
# info than you really need on how boot sectors are used, see
# http://support.microsoft.com/support/kb/articles/Q140/4/18.asp

# You can also edit dev.x to change the sizes of partitions. Don't
# forget, if you change the size of a FAT partition across the 32MB
# boundary, you need to change the type as well! Run "fdisk /dev/hda"
# or some such, then the l command to see the available partition
# types. Then go ahead and edit dev.x appropriately. Also, when moving
# partition boundarys with hand edits, make sure you move both logical
# and extended partition boundaries appropriately.

# Bad block checking right now is a quick read of the partition. A
# writing check is also possible but more difficult. You have to run
# badblocks as a separate command, and pass the bad block list to
# mke2fs in a file (in /tmp, which is a ram disk). You also have to
# know how large the blocks are, which you learn by running
# dumpe2fs. It gets messy and I haven't done it yet. You probably
# don't need it for a new hard drive, but if you have had a hard drive
# crash on you and you are reusing it (while you are waiting for its
# replacement to come in, I presume), then I highly recommend it. Let
# me know how you do it.

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.


# cut2fmt figures out the format string for the unpack function we use
# to slice and dice the output from fdisk. From Christiansen and
# Torkington, Perl Cookbook 5.

sub cut2fmt {
    my (@positions) = @_;
    my $template    = '';
    my $lastpos     = 1;

    foreach $place (@positions) {
        $template .= "A" . ($place - $lastpos) . " ";
        $lastpos = $place;
    }

    $template .= "A*";
    return $template;
}


# Sub gpl, a subroutine to ship the GPL and other header information
# to the current output file.

sub gpl {

print OUTPUT &lt;&lt;FINIS;

# Copyright 2001 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

FINIS

}


# Begin main line code.



# Provide a default device.

# print "\$ARGV[0] is $ARGV[0].\n";

$device = defined ($ARGV[0]) ? $ARGV[0] : "/dev/hda";

# Need to check to see if $device is a sym link. If it is, the mount
# point is the target of the link. (Mandrake) Otherwise we search for
# mount points on $device. Fedora, Red Hat.

if ( -l $device) {

    # It is a sym link. Get the target of the link, then make it into
    # an absolute path, preserving the numbering.

    $mountdev = '/dev/' . readlink ($device);
    $mountdev =~ s|ide/host(\d+)/bus(\d+)/target(\d+)/lun(\d+)/disc|ide/host\1/bus\2/target\3/lun\4|;
} else {
    # not a sym link; just assign it.
    $mountdev = $device;
}

# print "Device is $device; mount device is $mountdev.\n";

# Prepare format string. Here are two format strings I have found
# useful. Here, column numbers are 1 based, i.e. the leftmost column
# is column 1, not column 0 as in Emacs.

# We select a format string according to fdisk's version.

$fdpid = open (FDVER, "fdisk -v |") or die "Couldn't fork: $!\n";
while (&lt;FDVER&gt;) {
    @_ = unpack ("A7 A*", $_);
    $fdver=$_[1];
    $fdver =~ s/[^\d.]//g; # strip non-numbers, non-periods, as in "2.12pre".
}

# print "fdisk version is $fdver\n";

if ($fdver &lt; 2.12) {
# fdisk to 2.11?? Red Hat, Fedora Core 1
    $fmt = cut2fmt (11, 19, 24, 34, 45, 49);
} else {
# fdisk 2.12 &amp; up?? Mandrake 10.0, Fedora Core 2
    $fmt = cut2fmt (12, 14, 26, 38, 50, 55);
}
# print "Format string is $fmt.\n";

# define fields in the array @_.
$dev = 0;
$bootable = 1;
$firstcyl = 2;
$lastcyl = 3;
$parttype = 5;
$partstring = 6;

$target = "\/target";

$outputfilename = $device;
$outputfilename =~ s/\//./g;
$outputfilename = substr ($outputfilename, 1, 100);

$outputfilepath = "\/root\/bin\/";


# Make a hash of the labels.
$mpid = open (MOUNT, "mount -l |") or die "Couldn't fork: $!\n";
while (&lt;MOUNT&gt;) {
    if ($_ =~ /^$mountdev/i) { # is this a line with a partition in it?
#       print $_;               # print it just for grins
        split;
        if ($_[6] ne "") {      # only process if there actually is a label
            $_[6] =~ s/[\[\]]//g; # strike [ and ].
            $labels{$_[0]} = $_[6];
#           print "The label of file device $_[0] is $labels{$_[0]}.\n";
        }


        # We only mount if it's ext2fs or ext3fs and read and write.

        if ($_[4] =~ /ext[23]/ and $_[5] =~ /\(rw/ ) {
            if ($_[0] =~ /ide/i) {

                # We have a devfs system, e.g. Mandrake. This code
                # converts back from the devfs designation to the old
                # /dev/hd* designation for tomsrtb. I have NOT checked
                # this out for drives other than /dev/hda. Also, this
                # code does not handle SCSI drives.

                if ( $_[0] =~ /target0/ &amp;&amp; $_[0] =~ /bus0/ ) {
                    $letter = 'a';
                } elsif ( $_[0] =~ /target1/ &amp;&amp; $_[0] =~ /bus0/) {
                    $letter = 'b';
                } elsif ( $_[0] =~ /target0/ &amp;&amp; $_[0] =~ /bus1/) {
                    $letter = 'c';
                } else {
                    $letter = 'd';
                }
                $_[0] =~ s|/ide/host\d+/bus\d+/target\d+/lun\d+/part|/hd|g;
                $_[0] =~ s/hd/hd$letter/;
            }
            $mountpoints{$_[2]} = $_[0];
#             print "$_[2] is the mountpoint for tomsrtbt device $mountpoints{$_[2]}.\n";
        }
    }
}
close (MOUNT);


$fpid = open (FDISK, "fdisk -l $device |") or die "Couldn't fork: $!\n";

open (OUTPUT, "&gt; $outputfilepath${outputfilename}")
    or die "Couldn't open output file $outputfilepath${outputfilename}.\n";

while (&lt;FDISK&gt;) {
    if ($_ =~ /^$device/i) {    # is this a line with a partition in it?
#       print $_;               # print it just for grins
        chop;                   # kill trailing \r
        @_ = unpack ($fmt, $_);

        # now strip white spaces from cylinder numbers
        @_[$firstcyl] =~ s/[ \t]+//;
        @_[$lastcyl] =~ s/[ \t]+//;
        @_[$parttype] =~ s/[ \t]+//;

        $partnumber = substr(@_[$dev], 8, 10); # get partition number for this line
        # just for grins
#       print "  $partnumber, @_[$firstcyl], @_[$lastcyl], @_[$parttype], @_[$partstring]\n";

        # Here we start creating the input to recreate the partition
        # this line represents.

        print OUTPUT "n\n";
        if ($partnumber &lt; 5) {
            # primary Linux partition
            if (@_[$parttype] == 83) {
                print OUTPUT "p\n$partnumber\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) { # in case it's all on one cylinder
                    print OUTPUT "@_[$lastcyl]\n";
                }

                # Now detect if this is an ext3 (journaling)
                # partition. We do this using dumpe2fs to dump the
                # partition and grepping on "journal". If the
                # partition is ext2, there will be no output. If it is
                # ext3, there will be output, and we use that fact to
                # set a command line switch. The command line switch
                # goes into an associative array (hash) so we don't
                # have to remember to reset it to the null string when
                # we're done.

                $dpid = open (DUMPE2FS, "dumpe2fs @_[$dev] 2&gt;/dev/null | grep -i journal |")
                    or die "Couldn't fork: $!\n";
                while (&lt;DUMPE2FS&gt;) {
#                   print "Dumpe2fs: $_";
                    $ext3{$_[$dev]} = "-j ";
                    last;
                }
                close (DUMPE2FS);

                if ($labels{@_[$dev]}) { # do we have a label?
                    $format .= "echo\necho formatting $checking@_[$dev]\n";
                    $format .= "mke2fs $ext3{$_[$dev]}\$blockcheck -L $labels{@_[$dev]} @_[$dev]\n\n";
                } else {
                    $format .= "echo\necho formatting $checking@_[$dev]\n";
                    $format .= "mke2fs $ext3{$_[$dev]}\$blockcheck @_[$dev]\n\n";
                }

                # extended partition
            } elsif (@_[$parttype] == 5) {
                # print ("Creating Extended Partition.\n");
                print OUTPUT "e\n$partnumber\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) {
                    print OUTPUT "@_[$lastcyl]\n";
                }

                # extended partition, Win95 Ext'd (LBA)
            } elsif (@_[$parttype] eq "f") {
                # print ("Creating Extended LBA Partition.\n");
                print OUTPUT "e\n$partnumber\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) {
                    print OUTPUT "@_[$lastcyl]\n";
                }
                print OUTPUT "t\n$partnumber\nf\n";

                # primary Linux swap partition
            } elsif (@_[$parttype] == 82) {
                print OUTPUT "p\n$partnumber\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) {
                    print OUTPUT "@_[$lastcyl]\n";
                }
                print OUTPUT "t\n$partnumber\n82\n";
                $format .= "echo Making @_[$dev] a swap partition.\n";
                $format .= "mkswap \$blockcheck @_[$dev]\n\n";

                # Primary mess-dos partition. We don't handle hidden
                # partitions.
            } elsif ( @_[$parttype] == 1 || @_[$parttype] == 4 || @_[$parttype] == 6
                      || @_[$parttype] eq "b" || @_[$parttype] eq "c"
                      || @_[$parttype] eq "e" ) {
                # print ("Making DOS primary partition.\n");
                print ("dd if=@_[$dev] of=$outputfilepath$outputfilename$partnumber");
                print (" bs=512 count=1\n");
                system ("dd if=@_[$dev] of=$outputfilepath$outputfilename$partnumber bs=512 count=1");
                print OUTPUT "p\n$partnumber\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) { # in case it's all on one cylinder
                    print OUTPUT "@_[$lastcyl]\n";
                }
                print OUTPUT "t\n$partnumber\n@_[$parttype]\n";
                $format .= "echo\necho formatting $checking@_[$dev]\n";
                $format .= "mkdosfs \$blockcheck";
                if ( @_[$parttype] == b || @_[$parttype] == c) {
                    # We have a W9x FAT32 partition. Add a command line switch.
                    $format .= " -F 32";
                }
                $format .= " @_[$dev]\n";
                $format .= "# restore FAT boot sector.\n";
                $format .= "dd if=$outputfilename$partnumber of=@_[$dev] bs=512 count=1\n\n";

            } else {
                # anything else partition
                print OUTPUT "p\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) {
                    print OUTPUT "@_[$lastcyl]\n";
                }
                print OUTPUT "t\n$partnumber\n@_[$parttype]\n";
            }

        } else {
            # logical Linux partition
            if (@_[$parttype] == 83) {
                print OUTPUT "l\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) {
                    print OUTPUT "@_[$lastcyl]\n";
                }

                # Now detect if this is an ext3 (journaling)
                # partition. We do this using dumpe2fs to dump the
                # partition and grepping on "journal". If the
                # partition is ext2, there will be no output. If it is
                # ext3, there will be output, and we use that fact to
                # set a command line switch. The command line switch
                # goes into an associative array (hash) so we don't
                # have to remember to reset it to the null string when
                # we're done.

                $dpid = open (DUMPE2FS, "dumpe2fs @_[$dev] 2&gt;/dev/null | grep -i journal |")
                    or die "Couldn't fork: $!\n";
                while (&lt;DUMPE2FS&gt;) {
#                   print "Dumpe2fs: $_";
                    $ext3{$_[$dev]} = "-j ";
                    last;
                }
                close (DUMPE2FS);

                if ($labels{@_[$dev]}) { # do we have a label?
                    $format .= "echo\necho formatting $checking@_[$dev]\n";
                    $format .= "mke2fs $ext3{@_[$dev]}\$blockcheck -L $labels{@_[$dev]} @_[$dev]\n\n";
                } else {
                    $format .= "echo\necho formatting $checking@_[$dev]\n";
                    $format .= "mke2fs $ext3{@_[$dev]}\$blockcheck @_[$dev]\n\n";
                }

                # logical Linux swap partition
            } elsif (@_[$parttype] == 82 ) {
                print OUTPUT "l\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) {
                    print OUTPUT "@_[$lastcyl]\n";
                }
                print OUTPUT "t\n$partnumber\n82\n";
                $format .= "echo Making @_[$dev] a swap partition.\n";
                $format .= "mkswap \$blockcheck @_[$dev]\n\n";

                # Logical mess-dos partition. We don't handle hidden
                # partitions.

            } elsif ( @_[$parttype] == 1 || @_[$parttype] == 4 || @_[$parttype] == 6
                      || @_[$parttype] eq "b" || @_[$parttype] eq "c"
                      || @_[$parttype] eq "e" ) {
#               print ("Making DOS logical partition.\n");
                print ("dd if=@_[$dev] of=$outputfilepath$outputfilename$partnumber");
                print (" bs=512 count=1\n");
                system ("dd if=@_[$dev] of=$outputfilepath$outputfilename$partnumber bs=512 count=1");
                print OUTPUT "l\n$partnumber\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) { # in case it's all on one cylinder
                    print OUTPUT "@_[$lastcyl]\n";
                }
                print OUTPUT "t\n$partnumber\n@_[$parttype]\n";
                $format .= "echo\necho formatting $checking@_[$dev]\n";
                $format .= "mkdosfs \$blockcheck";
                if ( @_[$parttype] == b || @_[$parttype] == c) {
                    # We have a W9x FAT32 partition. Add a command line switch.
                    $format .= " -F 32";
                }
                $format .= " @_[$dev]\n";
                $format .= "# restore FAT boot sector.\n";
                $format .= "dd if=$outputfilename$partnumber of=@_[$dev] bs=512 count=1\n\n";

            } else {
                # anything else partition
                print OUTPUT "l\n@_[$firstcyl]\n";
                if (@_[$firstcyl] ne @_[$lastcyl]) {
                    print OUTPUT "@_[$lastcyl]\n";
                }
                print OUTPUT "t\n$partnumber\n@_[$parttype]\n";
            }

        }

        # handle bootable partitions
        if (@_[$bootable] =~ /\*/) {
            print OUTPUT "a\n$partnumber\n";
        }
    }
}

print OUTPUT "v\nw\n";

close (OUTPUT);
close (FDISK);


open (OUTPUT, "&gt; ${outputfilepath}make.$outputfilename")
    or die "Couldn't open output file ${outputfilepath}make.$outputfilename.\n";

print OUTPUT &lt;&lt;FINIS;
#! /bin/sh

# A script to restore the partition data of a hard drive and format
# the partitions. Created at bare metal backup time by the Perl script
# make.fdisk.
FINIS

&amp;gpl;

print OUTPUT &lt;&lt;FINIS;

export blockcheck=\$1;

if [ "\$blockcheck" != "-c" ] &amp;&amp; [ -n "\$blockcheck" ]
then
    echo "\${0}: automated restore with no human interaction."
    echo "\${0}: -c: block check during file system making."
    exit 1;
fi

FINIS

# Clean the old partition table out.
print OUTPUT "dd if=/dev/zero of=$device bs=512 count=2\n\nsync\n\n";

print OUTPUT "fdisk $device \&lt; $outputfilename\n\nsync\n\n";
print OUTPUT $format;

print OUTPUT "fdisk -l \"$device\"\n";

close (OUTPUT);

# Now build the script that will build the mount points on the root
# and other partitions.

open (OUTPUT, "&gt; ${outputfilepath}mount.$outputfilename")
    or die "Couldn't open output file ${outputfilepath}make.$outputfilename.\n";

print OUTPUT &lt;&lt;FINIS;
#! /bin/sh

# A script to create a minimal directory tree on the target hard drive
# and mount the partitions on it. Created at bare metal backup time by
# the Perl script make.fdisk.
FINIS

&amp;gpl;

print OUTPUT &lt;&lt;FINIS;

# WARNING: If your Linux system mount partitions across hard drive
# boundaries, you will have multiple "mount.dev.* scripts. You must
# ensure that they run in the proper order. The root partition should
# be mounted first, then the rest in the order they cascade. If they
# cross mount, you'll have to handle that manually.

FINIS


# We have a hash of mount points and devices in %mountpoints. However,
# we have to process them such that directories are built on the
# appropriate target partition. E.g. where /usr/local is on its own
# partition, we have to mount /usr before we build /usr/local. We can
# ensure this by sorting them. Shorter mount point paths will be built
# first. We can't sort a hash directly, so we use an array.

# We build commands to create the appropriate mount points and then
# mount the partitions to the mount points. This is in preparation for
# untarring the contents of the ZIP disk, done in restore.metadata.

foreach $point ( sort keys %mountpoints) {
    print OUTPUT "\n# $point is the mountpoint for tomsrtbt device $mountpoints{$point}.\n";
    print OUTPUT "mkdir $target$point\n";
    print OUTPUT "mount $mountpoints{$point} $target$point\n";
}

print OUTPUT "\nmount | grep -i \"$device\"\n";

close (OUTPUT);

# These scripts are dangerous &amp; should only be visible to root.

chmod 0700, "${outputfilepath}make.$outputfilename";
chmod 0700, "${outputfilepath}mount.$outputfilename";
chmod 0600, "${outputfilepath}$outputfilename";


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="make.dev.hda"></a>11.1.2.&nbsp;<code class="filename">make.dev.hda</code></h4></div></div></div><p>
	
    Ce script est un exemple de la production de <a href="ar01s11.html#make.fdisk" title="11.1.1.&nbsp;make.fdisk"><code class="filename">make.fdisk</code></a>, plus 
    haut. Il fait appel &agrave; des fichiers de donn&eacute;es comme <a href="ar01s11.html#dev.hda" title="11.1.4.&nbsp;dev.hda"><code class="filename">dev.hda</code></a>, plus bas. Il 
    cr&eacute;e des partitions et des syst&egrave;mes de fichiers sur certains d'entre 
    elles. C'est le premier script lanc&eacute; &agrave; la restauration.

</p><p>

    Si vous &ecirc;tes suffisamment courageux pour &eacute;diter <a href="ar01s11.html#dev.hda" title="11.1.4.&nbsp;dev.hda"><code class="filename">dev.hda</code></a> (voir plus 
    haut), pour, disons, ajouter une nouvelle partition, il se peut que 
    vous deviez &eacute;diter ce script.</p><p>

Si vous voulez que make.dev.hda v&eacute;rifie les secteurs d&eacute;fectueux quand il
installe un syst&egrave;me de fichiers sur les partitions, saisissez en ligne de
commande l'option "-c".</p><pre class="programlisting">
#! /bin/sh

# A script to restore the partition data of a hard drive and format
# the partitions. Created at bare metal backup time by the Perl script
# make.fdisk.

# Copyright 2001 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.


export blockcheck=$1;

if [ "$blockcheck" != "-c" ] &amp;&amp; [ -n "$blockcheck" ]
then
    echo "${0}: automated restore with no human interaction."
    echo "${0}: -c: block check during file system making."
    exit 1;
fi

dd if=/dev/zero of=/dev/hda bs=512 count=2

sync

fdisk /dev/hda &lt; dev.hda

sync

echo
echo formatting /dev/hda1
mkdosfs $blockcheck /dev/hda1
# restore FAT boot sector.
dd if=dev.hda1 of=/dev/hda1 bs=512 count=1

echo
echo formatting /dev/hda2
mke2fs -j $blockcheck -L /boot /dev/hda2

echo
echo formatting /dev/hda3
mke2fs -j $blockcheck -L / /dev/hda3

echo Making /dev/hda5 a swap partition.
mkswap $blockcheck /dev/hda5

fdisk -l "/dev/hda"


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="mount.dev.hda"></a>11.1.3.&nbsp;<code class="filename">mount.dev.hda</code></h4></div></div></div><p>

Ce script est un exemple de la production de <a href="ar01s11.html#make.fdisk" title="11.1.1.&nbsp;make.fdisk"><code class="filename">make.fdisk</code></a>, plus haut. 
Il cr&eacute;e des points de montage et monte les partitions, pr&eacute;parant le 
syst&egrave;me de fichiers cible &agrave; la restauration des fichiers. C'est le 
second script lanc&eacute; &agrave; la restauration.

</p><p>

Si vous &ecirc;tes suffisamment courageux pour &eacute;diter <a href="ar01s11.html#dev.hda" title="11.1.4.&nbsp;dev.hda"><code class="filename">dev.hda</code></a> (voir plus haut), 
pour, disons, ajouter une nouvelle partition, il se peut que vous deviez 
&eacute;diter ce script.

</p><pre class="programlisting">
#! /bin/sh

# A script to create a minimal directory tree on the target hard drive
# and mount the partitions on it. Created at bare metal backup time by
# the Perl script make.fdisk.

# Copyright 2001 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.


# WARNING: If your Linux system mount partitions across hard drive
# boundaries, you will have multiple "mount.dev.* scripts. You must
# ensure that they run in the proper order. The root partition should
# be mounted first, then the rest in the order they cascade. If they
# cross mount, you'll have to handle that manually.


# / is the mountpoint for /dev/hda3.
mkdir /target/
mount /dev/hda3 /target/

# /boot is the mountpoint for /dev/hda2.
mkdir /target/boot
mount /dev/hda2 /target/boot

mount | grep -i "/dev/hda"


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="dev.hda"></a>11.1.4.&nbsp;<code class="filename">dev.hda</code></h4></div></div></div><p>

    Ce fichier de donn&eacute;es est utilis&eacute; au moment de la restauration. Il 
    est utilis&eacute; par <span><strong class="command">fdisk</strong></span> et est aliment&eacute; par <a href="ar01s11.html#make.dev.hda" title="11.1.2.&nbsp;make.dev.hda"><code class="filename">make.dev.hda</code></a>. Il 
    est produit pendant la sauvegarde par <a href="ar01s11.html#make.fdisk" title="11.1.1.&nbsp;make.fdisk"><code class="filename">make.fdisk</code></a>. Ceux 
    qui connaissent bien <span><strong class="command">fdisk</strong></span> reconna&icirc;tront que 
    chaque ligne est une commande ou une valeur de 
    <span><strong class="command">fdisk</strong></span>, tel qu'un num&eacute;ro de cylindre. Donc, il est 
    possible de changer les tailles des partitions et d'ajouter de 
    nouvelles partitions en &eacute;ditant ce fichier. C'est pourquoi la 
    p&eacute;nulti&egrave;me commande est <span><strong class="command">v</strong></span>, qui v&eacute;rifiera la table 
    des partitions avant qu'elle soit &eacute;crite.

</p><pre class="programlisting">
n
p
1
1
29
t
1
6
a
1
n
p
2
30
44
n
e
3
45
1023
n
l
45
944
n
l
945
1023
t
6
82
v
w


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="save.metadata"></a>11.1.5.&nbsp;<code class="filename">save.metadata</code></h4></div></div></div><p>

C'est le premier script lanc&eacute; dans le processus de sauvegarde. Il 
appelle <a href="ar01s11.html#make.fdisk" title="11.1.1.&nbsp;make.fdisk"><code class="filename">make.fdisk</code></a>, plus haut. 
Si vous devez sauvegarder un disque dur SCSI ou plusieurs disques durs, 
faites de sorte que l'appel &agrave; <a href="ar01s11.html#make.fdisk" title="11.1.1.&nbsp;make.fdisk"><code class="filename">make.fdisk</code></a> soit 
effectu&eacute; de fa&ccedil;on correcte.

</p><pre class="programlisting">
#! /bin/sh

# A script to save certain meta-data off to the boot partition. Useful for
# restoration.

# Time-stamp: &lt;2004-04-29 15:36:52 root save.metadata&gt;

# Copyright 2000 through the last date of modification, Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/


# 2003 01 08: We now age the output from rpm -VA to make back
# comparisons easier.

# The loop that creates directories now has the -p option for mkdir,
# which means you can create parents on the fly if they don't already
# exist.

# initrd is now in the list of directories to create automatically.

# We now exclude more stuff when building the tarballs.

# 2002 07 01: Went to bzip2 to compress the archives, for smaller
# results. This is important in a 100MB ZIP disk. Also some general
# code cleanup.

# 2002 07 01: The function crunch will tar and BZIP2 the
# archives. This is cleaner than the old code, and has better safety
# checking.


# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.


# Crunch: A function to compress the contents of a directory and put
# the archive onto the ZIP disk.

# The first parameter is the name of the archive file to be
# created. The backup location, $zip, will be prepended and the
# extension, "tar.bz2" will be appended.

# All following parameters will be taken as additional directories or
# files to be put into the archive.

function crunch {

if [ -z "$1" ] || [ -z "$2" ]	# Checks if parameter #1 or #2 is zero length.
then
   echo "-Parameter #1 or #2 is missing.-"  # Also if no parameter is passed.
   return 1
else
   local file=$1		# The archive file to create
   shift			# Discard the file name
   local dirs=$@		# The director[y|ies] to archive
   local tarcmd="tar -cjf"	# The tar command.

   $tarcmd  $zip/$file.tar.bz2 $dirs # do it!!

   error=$?			# Preserve the exit code

   if [ $error != 0 ]		# Did we fail?
   then				# Yes
      echo "Tar failed with error $error"
      echo $tarcmd $zip/$file.tar.bz2 $dirs
      exit $error		# return tar's exit code as ours
   fi

   return 0			# For error testing if needed.
fi
}

# Begin the main line code
export zip="/mnt/zip";		# Where we will put archives
#  export save="/mnt/save";

RPMVABACKS=/etc			# where we keep our backups
RPMVAROOT=rpmVa			# The root name of the pg backups
ANC=${RPMVABACKS}/${RPMVAROOT}.anc	# name for the oldest (ancient) backup
OLD=${RPMVABACKS}/${RPMVAROOT}.old	# name for the middling oldest backup
NEW=${RPMVABACKS}/${RPMVAROOT}.txt	# name for the newest backup

if [ -f ${ANC} ]; then
echo "Deleting ${ANC}"
rm ${ANC}
fi

if [ -f ${OLD} ]; then
echo "Aging ${OLD}"
mv ${OLD} ${ANC}
fi

if [ -f ${NEW} ]; then
echo "Aging ${NEW}"
mv ${NEW} ${OLD}
fi


# Now we save hard drive information. Run make.fdisk on each hard
# drive in the order in which it mounted from the root partition. That
# is, run it first on the hard drive with your root partition, then
# any hard drives that mount to the first hard drive, then any hard
# drives that mount to those. For example, if your root partition is
# on /dev/sdc, run "make.fdisk /dev/sdc" first.

# The reason for this is that make.fdisk produces a script to make
# mount points and then mount the appropriate partition to them during
# first stage restore. Mount points must be created on the partition
# where they will reside. The partitions must be mounted in this
# order. For example, if your /var and /var/ftp are both separate
# partitions, then you must mount /, create /var, then mount /var,
# then create /var/ftp. The order in which the script "first.stage"
# runs the mounting scripts is based on their time of creation.

# If necessary, put a line, "sleep 1" between calls to make.fdisk.

echo "Saving hard drive info"
make.fdisk /dev/hda

# back up RPM metadata

echo "Verifying RPMs."

rpm -Va | sort +2 -t ' ' &gt; ${NEW}

echo "Finished verifying RPMs; now mounting the ZIP drive."

# Make sure we have the ZIP drive mounted.
umount $zip
modprobe ppa			# Driver for 100MB parallel port ZIP disk
mount $zip			# It should have ext2fs on partition 1.

# clean it all out
rm -r $zip/*
mkdir $zip/lost+found

echo "`hostname` bare metal ZIP disk, created `date`. `uname -a`" &gt; $zip/README.txt

echo "Building the ZIP drive backups."

# These are in case we need to refer to them while rebuilding. The
# rebuilding process should be mostly automated, but you never
# know....

fdisk -l /dev/hda &gt; $zip/fdisk.hda

ls -al /mnt &gt; $zip/ls.mnt.txt
ls -al / &gt; $zip/ls.root.txt

cd /

# Build our minimal archives on the ZIP disk. These appear to be
# required so we can restore later on.

crunch boot boot
crunch root root --exclude root/.cpan --exclude root/.mozilla
crunch etc etc --exclude etc/samba --exclude X11
crunch lib lib

crunch usr.sbin usr/sbin
crunch usr.bin usr/bin --exclude usr/bin/emacs --exclude usr/bin/emacs-21.2 --exclude usr/bin/emacsclient --exclude usr/bin/emacs-nox --exclude usr/bin/gs --exclude usr/bin/pine --exclude usr/bin/gimp-1.2 --exclude usr/bin/doxygen --exclude usr/bin/postgres --exclude usr/bin/gdb --exclude usr/bin/kmail --exclude usr/bin/splint --exclude usr/bin/odbctest --exclude usr/bin/php --exclude usr/bin/xchat --exclude usr/bin/gnucash --exclude usr/bin/pdfetex  --exclude usr/bin/pdftex --exclude usr/bin/smbcacls --exclude usr/bin/evolution-calendar --exclude usr/bin/xpdf --exclude usr/bin/xmms
crunch sbin sbin
crunch bin bin
crunch dev dev
crunch kerberos usr/kerberos/lib/

# Now optional saves.

# arkeia specific:
# crunch arkeia usr/knox

# save these so we can use ssh for restore. *crack* for RH 7.0 login
# authentication.
crunch usr.lib usr/lib/*crack* usr/lib/libz* usr/lib/libssl* usr/lib/libcrypto*

# save the scripts we used to create the ZIP disk and the ones we will
# use to restore it.
mkdir $zip/root.bin
cp -p /root/bin/* $zip/root.bin
rm $zip/root.bin/*~ $zip/root.bin/#*#

echo "Testing our results."
find $zip -iname "*.bz2" | xargs bunzip2 -t

# Not a normal part of the process: we duplicate the ZIP disk onto an
# NFS mount elsewhere.

#  echo "Backing the ZIP drive to the NFS mount."

#  umount $save
#  mount $save

#  rm -r $save/zip
#  mkdir $save/zip
#  cp -pr $zip $save

du -hs ${zip}*
df -m


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="restore.metadata"></a>11.1.6.&nbsp;<code class="filename">restore.metadata</code></h4></div></div></div><p>

Ce script restaure les m&eacute;tadonn&eacute;es du disque ZIP &agrave; la premi&egrave;re &eacute;tape de 
la restauration.

</p><pre class="programlisting">
#! /bin/sh

# A script to restore the meta-data from the ZIP disk. This runs under
# tomsrtbt only after partitions have been rebuilt, file systems made,
# and mounted. It also assumes the ZIP disk has already been
# mounted. Mounting the ZIP disk read only is probably a good idea.

# Time-stamp: &lt;2003-08-23 10:09:16 ccurley restore.metadata&gt;

# Copyright 2000 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# 2003 08 23: Oops: tar on tomsrtbt does not respect -p. Try setting
# umask to 0000 instead.

# 2003 02 13: Tar was not preserving permissions on restore. Fixed
# that.

# 2002 07 01: Went to bzip2 to compress the archives, for smaller
# results. This is important in a 100MB ZIP disk. Also some general
# code cleanup.

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

umask 0000

zip="/mnt";			# Where we mount the zip drive.
target="/target";		# Where the hard drive to restore is mounted.

ls -lt $zip			# Warm fuzzies for the user.

cd $target

# Restore the archived metadata files.
for archive in $( ls $zip/*.bz2 ); do
echo $archive
ls -al $archive
bzip2 -dc $archive | tar -xf -
done

# Build the mount points for our second stage restoration and other
# things.

# If you boot via an initrd, make sure you build a directory here so
# the kernel can mount the initrd at boot.

for dir in mnt/zip mnt/cdrom mnt/floppy mnt/imports proc initrd; do
mkdir -p $target/$dir
done

chmod a-w $target/proc		# Restore /proc's read-only permissions

# Restore the scripts we used to create the ZIP disk and the ones we will
# use to restore it. These should be the latest &amp; greatest in case we had
# to do any editing during 1st stage restore.
cp -p $zip/root.bin/* $target/root/bin

# Now install the boot sector.
chroot $target /sbin/lilo -C /etc/lilo.conf

df -m


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="first.stage"></a>11.1.7.&nbsp;<code class="filename">first.stage</code></h4></div></div></div><p>

Ce script effectue compl&egrave;tement la premi&egrave;re &eacute;tape de la restauration 
sans intervention humaine.

</p><p>

Si vous d&eacute;sirez v&eacute;rifier les secteurs d&eacute;fectueux pendant la cr&eacute;ation des 
syst&egrave;mes de fichiers des partitions, utilisez l'option de ligne de 
commande &laquo;&nbsp;<span class="quote">-c</span>&nbsp;&raquo;.

</p><pre class="programlisting">
#! /bin/sh

# A master script to run the other, detailed scripts. Use this script
# only if you want no human intervention in the restore process. The
# only option is -c, which forces bad block checking during formatting
# of the partitions.

# Time-stamp: &lt;2003-04-24 10:03:07 ccurley first.stage&gt;

# Copyright 2002 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

export blockcheck=$1;

if [ "$blockcheck" != "-c" ] &amp;&amp; [ -n "$blockcheck" ]
then
    echo "${0}: automated restore with no human interaction."
    echo "${0}: -c: block check during file system making."
    exit 1;
fi

cd /mnt/root.bin		# just in case we aren't already where we should be.

for drive in $( ls make.dev.* ); do
    ./$drive $blockcheck;
done


# WARNING: If your Linux system mount partitions across hard drive
# boundaries, you will have multiple "mount.dev.* scripts. You must
# ensure that they run in the proper order, which the loop below may
# not do. The root partition should be mounted first, then the rest in
# the order they cascade. If they cross mount, you'll have to handle
# that manually.

# The "ls -tr" will list the scripts in the order they are created, so
# it might be a good idea to create them (in the script save.metadata)
# in the order in which you should run them.

for drive in $( ls -tr mount.dev.* ); do
    ./$drive;
done

./restore.metadata

# People who are really confident may comment this line in.
# reboot

</pre></div></div><div class="sect2" lang="fr"><div class="titlepage"><div><div><h3 class="title"><a name="SecondStage"></a>11.2.&nbsp;Deuxi&egrave;me &eacute;tape</h3></div></div></div><p>

Ces scripts sont lanc&eacute;s sur l'ordinateur &agrave; sauvegarder ou restaurer.

</p><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="back.up.all"></a>11.2.1.&nbsp;<code class="filename">back.up.all</code></h4></div></div></div><p>

    Ce script effectue une sauvegarde vers un autre ordinateur via un 
    montage NFS. Vous pouvez l'adapter pour effectuer vos sauvegardes 
    vers une bande ou d'autres supports.

</p><pre class="programlisting">
#! /bin/sh

# Back up the entire system to another computer's drive. To make this
# work, we need a convenient chunk of disk space on the remote computer we
# can nfs mount as /mnt/save.

# Time-stamp: &lt;2003-04-24 09:56:05 ccurley back.up.all&gt;

# Copyright 2000 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

save="/mnt/save"

# Make sure it's there
umount $save
mount $save

cd /

rm $save/tester.tar.old.gz
mv $save/tester.tar.gz $save/tester.tar.old.gz

# save everything except /mnt, /proc, and nfs mounted directories.

time tar cf - / --exclude /mnt --exclude /proc --exclude $save\
    | gzip -c &gt; $save/tester.tar.gz



</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="back.up.all.ssh"></a>11.2.2.&nbsp;<code class="filename">back.up.all.ssh</code></h4></div></div></div><p>

    Ce script fait exactement la m&ecirc;me chose que <a href="ar01s11.html#back.up.all" title="11.2.1.&nbsp;back.up.all"><code class="filename">back.up.all</code></a> mais 
    il utilise ssh &agrave; la place de nfs.
    
</p><pre class="programlisting">
#! /bin/sh

# Back up the entire system to another computer's drive. To make this
# work, we need a convenient chunk of disk space on the remote
# computer. This version uses ssh to do its transfer, and compresses
# using bz2. This means this script has to know more about the other
# computer, which does not make for good modularization.

# Time-stamp: &lt;2003-04-24 09:56:52 ccurley back.up.all.ssh&gt;

# Copyright 2000 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

save="/backs/tester"
backup_server="charlesc"

# rotate the old backups. Do it all in one line to minimze authentication overhead.
ssh $backup_server "rm $save/tester.tar.old.bz2; mv $save/tester.tar.bz2 \
    $save/tester.tar.old.bz2"

# save everything except /mnt, /proc, and squid directories.

time tar cf - / --exclude /mnt --exclude /proc --exclude /var/spool/squid\
    | ssh $backup_server "bzip2 -9 &gt; $save/tester.tar.bz2"


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="restore.all"></a>11.2.3.&nbsp;<code class="filename">restore.all</code></h4></div></div></div><p>

Vous utiliserez ce script de restauration si votre sauvegarde a &eacute;t&eacute; 
effectu&eacute;e avec <a href="ar01s11.html#back.up.all" title="11.2.1.&nbsp;back.up.all"><code class="filename">back.up.all</code></a>.</p><pre class="programlisting">
#! /bin/sh

# A script to restore all of the data from an nfs mount. This is our final
# stage restore.

# Time-stamp: &lt;2003-04-24 09:58:51 ccurley restore.all&gt;

# Copyright 2000 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

export save="/mnt/save"

mount $save

cd /
gunzip -dc $save/tester.tar.gz | tar -xpkf -

rm /var/run/*.pid

lilo


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="restore.all.ssh"></a>11.2.4.&nbsp;<code class="filename">restore.all.ssh</code></h4></div></div></div><p>

Vous utiliserez ce script de restauration si votre sauvegarde a &eacute;t&eacute; 
effectu&eacute;e avec <a href="ar01s11.html#back.up.all.ssh" title="11.2.2.&nbsp;back.up.all.ssh"><code class="filename">back.up.all.ssh</code></a>.

</p><pre class="programlisting">
#! /bin/sh

# A script to restore all of the data using ssh and bunzip2. This is
# our final stage restore.

# Copyright 2000 through the last date of modification Charles Curley.

# Time-stamp: &lt;2003-04-24 09:59:10 ccurley restore.all.ssh&gt;

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

save="/backs/tester/"
backup_server="charlesc"

cd /

ssh $backup_server "cat $save/tester.tar.bz2" | bunzip2 | tar -xpkf -

rm /var/run/*.pid

lilo


</pre></div></div><div class="sect2" lang="fr"><div class="titlepage"><div><div><h3 class="title"><a name="BackupServerScripts"></a>11.3.&nbsp;Scripts de sauvegarde du serveur</h3></div></div></div><p>

Les scripts ssh d&eacute;crits ci-dessus sont susceptibles de poser un probl&egrave;me 
de s&eacute;curit&eacute;. Si vous les lancez derri&egrave;re un pare-feu, le pare-feu doit 
permettre &agrave; ssh d'acc&eacute;der au serveur de sauvegarde. Dans ce cas, il se 
peut qu'un pirate intelligent soit aussi capable de pirater le serveur 
de sauvegarde. Il serait plus s&ucirc;r d'ex&eacute;cuter les scripts de sauvegarde 
et de restauration sur le serveur de sauvegarde, et de laisser le 
serveur de sauvegarde acc&eacute;der au pare-feu. Ces scripts sont con&ccedil;us pour 
fonctionner ainsi. Renommez-les en <code class="filename">get.x</code> et en 
<code class="filename">restore.x</code> o&ugrave; <code class="filename">x</code> est le nom de 
l'ordinateur cible. &Eacute;ditez-les (la variable $target 
d'initialisation d&eacute;finissant la cible) pour qu'ils utilisent le nom 
d'h&ocirc;te de l'ordinateur cible, ou r&eacute;&eacute;crivez-les pour qu'ils utilisent un 
argument de ligne de commande.

</p><p>

    Ces scripts effectuent compl&egrave;tement la sauvegarde et la restauration 
    de la cible, et pas uniquement la premi&egrave;re &eacute;tape de la sauvegarde et 
    de la restauration. Remarquez aussi que 
    <code class="filename">get.tester</code> sauvegarde aussi le disque ZIP, au 
    cas o&ugrave; vous auriez besoin de remplacer un disque ZIP d&eacute;fectueux.

</p><p>

    J'utilise couramment ces scripts.

</p><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="get.tester"></a>11.3.1.&nbsp;<code class="filename">get.tester</code></h4></div></div></div><pre class="programlisting">
#! /bin/sh

# Back up another computer's drive to this system. To make this work, we
# need a convenient chunk of disk space on this computer. This version
# uses ssh to do its transfer, and compresses using bz2. This version was
# developed so that the system to be backed up won't be authenticated to
# log onto the backup computer. This script is intended to be used on a
# firewall. You don't want the firewall to be authenticated to the backup
# system in case the firewall is cracked.

# Time-stamp: &lt;2004-04-03 12:24:12 ccurley get.tester&gt;

# Copyright 2000 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

# 2004 04 03: added /sys to the list of excludes. It is a read-only
# pseudo-file system like /proc.

# 2002 07 01: We now set the path on the target to the zip drive with
# a variable. This fixes a bug in the command to eject the zip disk.

# 2002 07 01: The zip disk archives are now in bzip2 format, so this
# script has been changed to reflect that.



# The host name of the computer to be backed up.
target=tester
zip=/mnt/zip

echo Backing up $target

echo Aging the ZIP disk backups.

rm -r $target.old.zip

mv $target.zip $target.old.zip

ssh $target "modprobe ppa ; mount -r $zip"

echo Copying the ZIP disk.

# -r for recursive copy, -p to preserve times and permissions, -q for
# quiet: no progress meter.

scp -qpr $target:$zip $target.zip

du -hs $target.zip


echo Aging the archives

rm $target.tar.old.bz2

mv $target.tar.bz2 $target.tar.old.bz2


echo Backing up $target to the backup server.

ssh $target tar -cf - / --exclude /sys --exclude /mnt --exclude /proc\
    --exclude /var/spool/squid\
    | bzip2 -9 | cat &gt; $target.tar.bz2

echo Testing the results.
find . -iname "*.bz2" | xargs bunzip2 -t

ssh $target "eject $zip"


</pre></div><div class="sect3" lang="fr"><div class="titlepage"><div><div><h4 class="title"><a name="restore.tester"></a>11.3.2.&nbsp;<code class="filename">restore.tester</code></h4></div></div></div><pre class="programlisting">
#! /bin/sh

# A script to restore all of the data to tester via ssh. This is our final
# stage restore.

# Time-stamp: &lt;2003-04-24 09:59:45 ccurley restore.tester&gt;

# Copyright 2000 through the last date of modification Charles Curley.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# You can also contact the Free Software Foundation at http://www.fsf.org/

# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.

# The host name of the computer to be restored.

target=tester

bunzip2 -dc $target.tar.bz2 | ssh $target "cd / ; tar -xpkf - "

ssh $target lilo


</pre></div></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="ar01s10.html">Pr&eacute;c&eacute;dent</a>&nbsp;</td><td align="center" width="20%">&nbsp;</td><td align="right" width="40%">&nbsp;<a accesskey="n" href="ar01s12.html">Suivant</a></td></tr><tr><td valign="top" align="left" width="40%">10.&nbsp;Et maintenant&nbsp;?&nbsp;</td><td align="center" width="20%"><a accesskey="h" href="index.html">Sommaire</a></td><td valign="top" align="right" width="40%">&nbsp;12.&nbsp;Ressources</td></tr></table></div></body></html>