Changeset 2119 in MondoRescue for devel


Ignore:
Timestamp:
Jan 12, 2009, 1:53:26 PM (15 years ago)
Author:
Bruno Cornec
Message:

Code reorganisation for devel every script under sbin and first attempt for a new LVM analysis

Location:
devel/mindi/sbin
Files:
1 deleted
2 copied
1 moved

Legend:

Unmodified
Added
Removed
  • devel/mindi/sbin/mranalyze-lvm

    r2090 r2119  
    22#
    33# Analyze the LVM configuration
    4 # and stor the configuration for restore time
     4# and store the configuration for restore time
    55#
    66# $Id$
     
    2828=head1 NAME
    2929
    30 Analyze-lvm - A Mindi Tool to analyze the LVM configuration and store it
     30mranalyze-lvm - A Mindi Tool to analyze the LVM configuration and store it
    3131
    3232=head1 DESCRIPTION
    3333
    34 B<anlyze-lvm> prints all the information related to the LVM configuration that may be used by a restoration process
     34B<mranalyze-lvm> prints all the information related to the LVM configuration that may be used by a restoration process
    3535
    3636=head1 SYNOPSIS
    3737
    38 analyze-lvm [-v]|[-q]|[-h]|[--man]
     38mranalyze-lvm [-v]|[-q]|[-h]|[--man][-o outputfile][-l logfile]
    3939
    4040=head1 OPTIONS
     
    4444=item B<-v|--verbose>
    4545
    46 Print a brief help message and exits.
    47 
     46Be more verbose
    4847
    4948=item B<-q|--quiet>
     
    5958Prints the manual page and exits.
    6059
    61 =item B<-i|--iso iso_image>
     60=item B<-o|--output>
    6261
    63 Name of the ISO image you want to created.
     62Name of the file to generate. Use stdout by default
     63
     64The output format is:
     65LVM:lvm-version
     66PV:pv-information as done with pvdisplay -c
     67VG:vg-information as done with vgdisplay -c
     68LV:lv-information as done with lvdisplay -c
    6469
    6570=back
     
    7176=head1 USER MAILING LIST
    7277
    73 The miling list of the project is available at L<mailto:mondo@lists.sf.net>
     78The mailing list of the project is available at L<mailto:mondo@lists.sf.net>
    7479 
    7580=head1 AUTHORS
     
    8691
    8792# ---------------------------------------------------------------------------
     93# Globals
     94my %opts;                   # CLI Options
    8895
    8996# Initialize the syntax string
    9097
    91 pb_syntax_init("analyze-lvm Version PBVER-rPBREV\n");
     98pb_syntax_init("mranalyze-lvm Version PBVER-rPBREV\n");
    9299
    93100# Handle options
     
    97104        "verbose|v+" => \$opts{'v'},
    98105        "quiet|q" => \$opts{'q'},
     106        "output|o=s" => \$opts{'o'},
    99107        "log-files|l=s" => \$opts{'l'},
    100108        "version|V" => \$opts{'V'},
     
    128136pb_temp_init();
    129137
    130 my $lvmds = "/usr/sbin/lvmdiskscan";
    131 my $lvmproc = "/proc/lvm/global";
    132 my $lvmcmd = "/usr/sbi/lvm";
     138# -------------------------------- main -----------------------------------
     139my ($lvmver,$lvmcmd) = mr_lvm_check();
    133140
    134 # -------------------------------- main -----------------------------------
    135 mr_exit(-1,"$lvmds doesn't exist. No LVM handling.") if ((! -x $lvmds) ;
    136 mr_exit(-1,"$lvmproc doesn't exist. No LVM handling.") if ((! -x $lvmproc) ;
     141# Where to send the output
     142my $OUTPUT = \*STDOUT;
     143if (defined $opts{'o'}) {
     144    open(OUTPUT, "> $opts{'o'}") || mr_exit(-1, "Unable to write to $opts{'o'}");
     145    $OUTPUT = \*OUTPUT;
     146}
    137147
    138 # Check LVM volumes presence
    139 open(LVM,$lvmproc) || mr_exit(-1,"Unable to open $lvmproc");
     148print $OUTPUT "LVM:$lvmver";
     149
     150# Analyze the existing physical volumes
     151open(LVM,"$lvmcmd pvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd pvdisplay -c");
    140152while (<LVM>) {
    141     mr_exit(1,"No LVM volumes found in $lvmproc") if (/0 VGs 0 PVs 0 LVs/);
     153        print $OUTPUT "PV:$_";
    142154}
    143155close(LVM);
    144156
    145 # Check LVM version
    146 my $lvmver=0;
    147 open(LVM,"$lvmds --help 2>&1 |") || mr_exit(-1,"Unable to execute $lvmds");
     157# Analyze the existing volume groups
     158open(LVM,"$lvmcmd vgdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd vgdisplay -c");
    148159while (<LVM>) {
    149         if (/Logical Volume Manager/ || /LVM version:/) {
    150                 $lvmver = $_;
    151                 $lvmver =~ s/:([0-9])\..*/$1/;
    152         }
     160        print $OUTPUT "VG:$_";
    153161}
    154162close(LVM);
    155 #lvmversion=`lvmdiskscan --help 2>&1 |
    156 #grep -E "Logical Volume Manager|LVM version:" |
    157 #cut -d: -f2 | cut -d. -f1 |
    158 #awk '{print $NF}' |
    159 #sed -e 's/ //g'`
    160163
    161 if ($lvmver = 0) {
    162     # Still not found
    163     if (-x $lvmcmd) {
    164         open(LVM,"$lvmcmd version |") || mr_exit(-1,"Unable to execute $lvmcmd");
    165         while (<LVM>) {
    166             if (/LVM version/) {
    167                 $lvmver = $_;
    168                 $lvmver =~ s/LVM version ([0-9])\..*/$1/;
    169             }
    170         }
    171         close(LVM);
    172     }
    173 }
    174 
    175 if ($lvmver = 0) {
    176     # Still not found
    177     mr_exit(-1,"Unable to determine LVM version.\nPlease report to the dev team with the result of the commands\n$lvmds and $lvmvmd version");
    178 } elsif ($lvmver = 1) {
    179     $lvmcmd = "";
    180 }
    181 pb_log(0,"Found LVM version $lvmver");
    182 
    183 # For the moment on stdout
    184 OUTPUT = \*STDOUT;
    185 
    186 # Generate the startup scrit on the fly needed to restore LVM conf
    187 print OUTPUT "# Desactivate Volume Groups\n";
    188 print OUTPUT "$lvmcmd vgchange -an\n";
    189 print OUTPUT "\n";
    190 
    191 print OUTPUT "# Creating Physical Volumes\n";
    192 # Analyze the existing physical volumes
    193 open(LVM,"$lvmcmd pvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd pvdisplay -c");
     164# Analyze the existing logical volumes
     165open(LVM,"$lvmcmd lvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd lvdisplay -c");
    194166while (<LVM>) {
    195         my ($pvname,$vgname,$pvsize,$ipvn,$pvstat,$pvna,$lvnum,$pesize,$petot,$pefree,$pelloc) = split(/:/);
    196         print OUTPUT "$lvmcmd pvcreate -ff -y -s $pesize $pvname\n";
     167        print $OUTPUT "LV:$_";
    197168}
    198169close(LVM);
    199 print OUTPUT "\n";
    200 print OUTPUT "# Scanning again Volume Groups\n";
    201 print OUTPUT "$lvmcmd vgscan\n";
    202 print OUTPUT "\n";
    203170
    204 # Analyze the existing volume groups
    205 print OUTPUT "# Creating Volume Groups and Activating them\n";
    206 open(LVM,"$lvmcmd vgdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd vgdisplay -c");
    207 while (<LVM>) {
    208     my ($vgname,$vgaccess,$vgstat,$vgnum,$lvmaxnum,$lvnum,$ocalvinvg,$lvmaxsize,$pvmaxnum,$cnumpv,$anumpv,$vgsize,$pesize,$penum,$pealloc,$pefree,$uuid) = split(/:/);
    209     if ($lvmver < 2) {
    210         print OUTPUT "# Removing device first as LVM v1 doesn't do it\n";
    211         print OUTPUT "rm -Rf /dev/$vg\n";
    212     }
    213     $lvmaxnum = 255 if ($lvmaxnum > 256);
    214     $pvmaxnum = 255 if ($pvmaxnum > 256);
    215     print OUTPUT "# Create Volume Group $vgname\n";
    216     # Pb sur pesize unite ?
    217     print OUTPUT "$lvmcmd vgcreate $vgname -p $pvmaxnum -s $pesize -l $lvmaxnum $lvmaxnum\n";
     171mr_exit(0,undef);
     172
     173sub mr_exit {
     174
     175my $code = shift;
     176my $msg = shift;
     177
     178close(OUTPUT);
     179print $msg."\n" if ((defined $msg) and ($pbdebug >= 0));
     180die "ERROR returned\n" if ($code < 0);
     181print "No LVM handling\n" if (($code > 0) and ($pbdebug >= 0));
     182exit($code);
    218183}
    219 close(LVM);
    220 print OUTPUT "\n";
    221 print OUTPUT "# Activate Volume Group $vg\n";
    222 print OUTPUT "$lvmcmd vgchange -ay\n";
    223 print OUTPUT "\n";
    224 
    225 print OUTPUT "# Creating Logical Volumes\n";
    226 open(LVM,"$lvmcmd lvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd lvdisplay -c");
    227 while (<LVM>) {
    228     my ($lvname,$vgname,$lvaccess,$lvstat,$lvnum,$oclv,$lvsize,$leinlv,$lealloc,$allocpol,$reaadhead,$major,$minor) = split(/:/);
    229     print OUTPUT "# Create Logical Volume $lvname\n";
    230     print OUTPUT "$lvmcmd lvcreate -n $lvname -L $lvsize -r $redahed $vgname\n";
    231     [ "$stripes" ]    && output="$output -i $stripes"
    232     [ "$stripesize" ] && output="$output -I $stripesize"
    233 }
    234 close(LVM);
    235 print OUTPUT "\n";
    236 print OUTPUT "# Scanning again Volume Groups\n";
    237 print OUTPUT "$lvmcmd vgscan\n";
    238 print OUTPUT "\n";
    239 
    240 WriteShutdownScript
    241 mr_exit(0,"End of analyze-lvm");
  • devel/mindi/sbin/mrprepare-lvm

    r2090 r2119  
    2828=head1 NAME
    2929
    30 Analyze-lvm - A Mindi Tool to analyze the LVM configuration and store it
     30mrprepare-lvm - A Mindi Tool to restore the LVM configuration and apply it
    3131
    3232=head1 DESCRIPTION
    3333
    34 B<anlyze-lvm> prints all the information related to the LVM configuration that may be used by a restoration process
     34B<mrprepare-lvm> gets all the information related to the LVM configuration from stdin or a file and prepare a restoration script
    3535
    3636=head1 SYNOPSIS
    3737
    38 analyze-lvm [-v]|[-q]|[-h]|[--man]
     38mrprepare-lvm [-v]|[-q]|[-h]|[--man][-i inputfile][-l logfile][-m multiplier]
    3939
    4040=head1 OPTIONS
     
    4444=item B<-v|--verbose>
    4545
     46Be more verbose
     47
     48=item B<-q|--quiet>
     49
     50Do not print any output.
     51
     52=item B<-h|--help>
     53
    4654Print a brief help message and exits.
    4755
    48 
    49 =item B<-q|--quiet>
    50 
    51 Do not print any output.
    52 
    53 =item B<-h|--help>
    54 
    55 Print a brief help message and exits.
    56 
    5756=item B<--man>
    5857
    5958Prints the manual page and exits.
    6059
    61 =item B<-i|--iso iso_image>
    62 
    63 Name of the ISO image you want to created.
     60=item B<-i|--input>
     61
     62Name of the file to get input from. Use stdin by default
     63
     64The input format is:
     65LVM:lvm-version
     66PV:pv-information as done with pvdisplay -c
     67VG:vg-information as done with vgdisplay -c
     68LV:lv-information as done with lvdisplay -c
     69
     70=item B<-o|--output>
     71
     72Name of the file to write output to. Use stdout by default.
     73The output file is a srpit ready to run in order to setup correctly LVM
     74
    6475
    6576=back
     
    7182=head1 USER MAILING LIST
    7283
    73 The miling list of the project is available at L<mailto:mondo@lists.sf.net>
     84The mailing list of the project is available at L<mailto:mondo@lists.sf.net>
    7485 
    7586=head1 AUTHORS
     
    8697
    8798# ---------------------------------------------------------------------------
     99# Globals
     100my %opts;                   # CLI Options
    88101
    89102# Initialize the syntax string
    90103
    91 pb_syntax_init("analyze-lvm Version PBVER-rPBREV\n");
     104pb_syntax_init("mrprepare-lvm Version PBVER-rPBREV\n");
    92105
    93106# Handle options
     
    97110        "verbose|v+" => \$opts{'v'},
    98111        "quiet|q" => \$opts{'q'},
     112        "input|i=s" => \$opts{'o'},
     113        "output|o=s" => \$opts{'o'},
     114        "multiplier|m=s" => \$opts{'o'},
    99115        "log-files|l=s" => \$opts{'l'},
    100116        "version|V" => \$opts{'V'},
     
    112128}
    113129if (defined $opts{'q'}) {
    114     $pbdebug=-1;
     130    $pbdebug = -1;
     131}
     132my $mrmult = 1;
     133if (defined $opts{'m'}) {
     134    $mrmult = $opts{'m'};
    115135}
    116136
     
    128148pb_temp_init();
    129149
    130 my $lvmds = "/usr/sbin/lvmdiskscan";
    131 my $lvmproc = "/proc/lvm/global";
    132 my $lvmcmd = "/usr/sbi/lvm";
    133 
    134150# -------------------------------- main -----------------------------------
    135 mr_exit(-1,"$lvmds doesn't exist. No LVM handling.") if ((! -x $lvmds) ;
    136 mr_exit(-1,"$lvmproc doesn't exist. No LVM handling.") if ((! -x $lvmproc) ;
    137 
    138 # Check LVM volumes presence
    139 open(LVM,$lvmproc) || mr_exit(-1,"Unable to open $lvmproc");
    140 while (<LVM>) {
    141     mr_exit(1,"No LVM volumes found in $lvmproc") if (/0 VGs 0 PVs 0 LVs/);
    142 }
    143 close(LVM);
    144 
    145 # Check LVM version
    146 my $lvmver=0;
    147 open(LVM,"$lvmds --help 2>&1 |") || mr_exit(-1,"Unable to execute $lvmds");
    148 while (<LVM>) {
    149         if (/Logical Volume Manager/ || /LVM version:/) {
    150                 $lvmver = $_;
    151                 $lvmver =~ s/:([0-9])\..*/$1/;
     151my ($lvmver,$lvmcmd) = mr_lvm_check();
     152
     153# Where to send the output
     154my $OUTPUT = \*STDOUT;
     155if (defined $opts{'o'}) {
     156    open(OUTPUT, "> $opts{'o'}") || mr_exit(-1, "Unable to write to $opts{'o'}");
     157    $OUTPUT = \*OUTPUT;
     158}
     159
     160# Where to get the input
     161my $INPUT = \*STDIN;
     162if (defined $opts{'i'}) {
     163    open(INPUT, " $opts{'i'}") || mr_exit(-1, "Unable to read from $opts{'i'}");
     164    $INPUT = \*INPUT;
     165}
     166
     167
     168# Generate the startup scrit needed to restore LVM conf
     169# from what is given on input
     170# Multiply by the multiplier given in input or 1 of none
     171print $OUTPUT "# Desactivate Volume Groups\n";
     172print $OUTPUT "$lvmcmd vgchange -an\n";
     173print $OUTPUT "\n";
     174
     175my $firsttime = 0;
     176while (<INPUT>) {
     177    if (/^PV:/) {
     178        my ($tag,$pvname,$vgname,$pvsize,$ipvn,$pvstat,$pvna,$lvnum,$pesize,$petot,$pefree,$pelloc) = split(/:/);
     179        print $OUTPUT "# Creating Physical Volumes $pvname\n";
     180        print $OUTPUT "$lvmcmd pvcreate -ff -y -s ".$pesize*$mrmult." $pvname\n";
     181        print $OUTPUT "\n";
     182    } elsif (/^VG:/) {
     183        my ($tag,$vgname,$vgaccess,$vgstat,$vgnum,$lvmaxnum,$lvnum,$ocalvinvg,$lvmaxsize,$pvmaxnum,$cnumpv,$anumpv,$vgsize,$pesize,$penum,$pealloc,$pefree,$uuid) = split(/:/);
     184        if ($lvmver < 2) {
     185            print $OUTPUT "# Removing device first as LVM v1 doesn't do it\n";
     186            print $OUTPUT "rm -Rf /dev/$vgname\n";
    152187        }
    153 }
    154 close(LVM);
    155 #lvmversion=`lvmdiskscan --help 2>&1 |
    156 #grep -E "Logical Volume Manager|LVM version:" |
    157 #cut -d: -f2 | cut -d. -f1 |
    158 #awk '{print $NF}' |
    159 #sed -e 's/ //g'`
    160 
    161 if ($lvmver = 0) {
    162     # Still not found
    163     if (-x $lvmcmd) {
    164         open(LVM,"$lvmcmd version |") || mr_exit(-1,"Unable to execute $lvmcmd");
    165         while (<LVM>) {
    166             if (/LVM version/) {
    167                 $lvmver = $_;
    168                 $lvmver =~ s/LVM version ([0-9])\..*/$1/;
    169             }
     188        $lvmaxnum = 255 if ($lvmaxnum > 256);
     189        $pvmaxnum = 255 if ($pvmaxnum > 256);
     190        print $OUTPUT "# Create Volume Group $vgname\n";
     191        # Pb sur pesize unite ?
     192        print $OUTPUT "$lvmcmd vgcreate $vgname -p $pvmaxnum -s $pesize -l $lvmaxnum\n";
     193        print $OUTPUT "\n";
     194    } elsif (/^LV:/) {
     195        if ($firsttime eq 0) {
     196            print $OUTPUT "\n";
     197            print $OUTPUT "# Activate All Volume Groups\n";
     198            print $OUTPUT "$lvmcmd vgchange -ay\n";
     199            print $OUTPUT "\n";
    170200        }
    171         close(LVM);
     201        my ($tag,$lvname,$vgname,$lvaccess,$lvstat,$lvnum,$oclv,$lvsize,$leinlv,$lealloc,$allocpol,$readahead,$major,$minor) = split(/:/);
     202        print $OUTPUT "# Create Logical Volume $lvname\n";
     203        print $OUTPUT "$lvmcmd lvcreate -n $lvname -L ".$lvsize*$mrmult." -r $readahead $vgname\n";
     204        #[ "$stripes" ]    && output="$output -i $stripes"
     205        #[ "$stripesize" ] && output="$output -I $stripesize"
    172206    }
    173207}
    174 
    175 if ($lvmver = 0) {
    176     # Still not found
    177     mr_exit(-1,"Unable to determine LVM version.\nPlease report to the dev team with the result of the commands\n$lvmds and $lvmvmd version");
    178 } elsif ($lvmver = 1) {
    179     $lvmcmd = "";
    180 }
    181 pb_log(0,"Found LVM version $lvmver");
    182 
    183 # For the moment on stdout
    184 OUTPUT = \*STDOUT;
    185 
    186 # Generate the startup scrit on the fly needed to restore LVM conf
    187 print OUTPUT "# Desactivate Volume Groups\n";
    188 print OUTPUT "$lvmcmd vgchange -an\n";
    189 print OUTPUT "\n";
    190 
    191 print OUTPUT "# Creating Physical Volumes\n";
    192 # Analyze the existing physical volumes
    193 open(LVM,"$lvmcmd pvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd pvdisplay -c");
    194 while (<LVM>) {
    195         my ($pvname,$vgname,$pvsize,$ipvn,$pvstat,$pvna,$lvnum,$pesize,$petot,$pefree,$pelloc) = split(/:/);
    196         print OUTPUT "$lvmcmd pvcreate -ff -y -s $pesize $pvname\n";
    197 }
    198 close(LVM);
    199 print OUTPUT "\n";
    200 print OUTPUT "# Scanning again Volume Groups\n";
    201 print OUTPUT "$lvmcmd vgscan\n";
    202 print OUTPUT "\n";
    203 
    204 # Analyze the existing volume groups
    205 print OUTPUT "# Creating Volume Groups and Activating them\n";
    206 open(LVM,"$lvmcmd vgdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd vgdisplay -c");
    207 while (<LVM>) {
    208     my ($vgname,$vgaccess,$vgstat,$vgnum,$lvmaxnum,$lvnum,$ocalvinvg,$lvmaxsize,$pvmaxnum,$cnumpv,$anumpv,$vgsize,$pesize,$penum,$pealloc,$pefree,$uuid) = split(/:/);
    209     if ($lvmver < 2) {
    210         print OUTPUT "# Removing device first as LVM v1 doesn't do it\n";
    211         print OUTPUT "rm -Rf /dev/$vg\n";
    212     }
    213     $lvmaxnum = 255 if ($lvmaxnum > 256);
    214     $pvmaxnum = 255 if ($pvmaxnum > 256);
    215     print OUTPUT "# Create Volume Group $vgname\n";
    216     # Pb sur pesize unite ?
    217     print OUTPUT "$lvmcmd vgcreate $vgname -p $pvmaxnum -s $pesize -l $lvmaxnum $lvmaxnum\n";
    218 }
    219 close(LVM);
    220 print OUTPUT "\n";
    221 print OUTPUT "# Activate Volume Group $vg\n";
    222 print OUTPUT "$lvmcmd vgchange -ay\n";
    223 print OUTPUT "\n";
    224 
    225 print OUTPUT "# Creating Logical Volumes\n";
    226 open(LVM,"$lvmcmd lvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd lvdisplay -c");
    227 while (<LVM>) {
    228     my ($lvname,$vgname,$lvaccess,$lvstat,$lvnum,$oclv,$lvsize,$leinlv,$lealloc,$allocpol,$reaadhead,$major,$minor) = split(/:/);
    229     print OUTPUT "# Create Logical Volume $lvname\n";
    230     print OUTPUT "$lvmcmd lvcreate -n $lvname -L $lvsize -r $redahed $vgname\n";
    231     [ "$stripes" ]    && output="$output -i $stripes"
    232     [ "$stripesize" ] && output="$output -I $stripesize"
    233 }
    234 close(LVM);
    235 print OUTPUT "\n";
    236 print OUTPUT "# Scanning again Volume Groups\n";
    237 print OUTPUT "$lvmcmd vgscan\n";
    238 print OUTPUT "\n";
    239 
    240 WriteShutdownScript
    241 mr_exit(0,"End of analyze-lvm");
     208print $OUTPUT "\n";
     209print $OUTPUT "# Scanning again Volume Groups\n";
     210print $OUTPUT "$lvmcmd vgscan\n";
     211print $OUTPUT "\n";
     212
     213
     214#WriteShutdownScript
     215mr_exit(0,"End of mrprepare-lvm");
     216
     217sub mr_exit {
     218
     219my $code = shift;
     220my $msg = shift || "";
     221
     222close(OUTPUT);
     223print $msg."\n";
     224die "ERROR returned\n" if ($code < 0);
     225print "No LVM handling\n" if ($code > 0);
     226exit(0);
     227}
Note: See TracChangeset for help on using the changeset viewer.