Changeset 2119 in MondoRescue for devel/mindi/sbin/mranalyze-lvm
- Timestamp:
- Jan 12, 2009, 1:53:26 PM (15 years ago)
- Location:
- devel/mindi/sbin
- Files:
-
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
devel/mindi/sbin/mranalyze-lvm
r2090 r2119 2 2 # 3 3 # Analyze the LVM configuration 4 # and stor the configuration for restore time4 # and store the configuration for restore time 5 5 # 6 6 # $Id$ … … 28 28 =head1 NAME 29 29 30 Analyze-lvm - A Mindi Tool to analyze the LVM configuration and store it30 mranalyze-lvm - A Mindi Tool to analyze the LVM configuration and store it 31 31 32 32 =head1 DESCRIPTION 33 33 34 B< anlyze-lvm> prints all the information related to the LVM configuration that may be used by a restoration process34 B<mranalyze-lvm> prints all the information related to the LVM configuration that may be used by a restoration process 35 35 36 36 =head1 SYNOPSIS 37 37 38 analyze-lvm [-v]|[-q]|[-h]|[--man]38 mranalyze-lvm [-v]|[-q]|[-h]|[--man][-o outputfile][-l logfile] 39 39 40 40 =head1 OPTIONS … … 44 44 =item B<-v|--verbose> 45 45 46 Print a brief help message and exits. 47 46 Be more verbose 48 47 49 48 =item B<-q|--quiet> … … 59 58 Prints the manual page and exits. 60 59 61 =item B<- i|--iso iso_image>60 =item B<-o|--output> 62 61 63 Name of the ISO image you want to created. 62 Name of the file to generate. Use stdout by default 63 64 The output format is: 65 LVM:lvm-version 66 PV:pv-information as done with pvdisplay -c 67 VG:vg-information as done with vgdisplay -c 68 LV:lv-information as done with lvdisplay -c 64 69 65 70 =back … … 71 76 =head1 USER MAILING LIST 72 77 73 The m iling list of the project is available at L<mailto:mondo@lists.sf.net>78 The mailing list of the project is available at L<mailto:mondo@lists.sf.net> 74 79 75 80 =head1 AUTHORS … … 86 91 87 92 # --------------------------------------------------------------------------- 93 # Globals 94 my %opts; # CLI Options 88 95 89 96 # Initialize the syntax string 90 97 91 pb_syntax_init(" analyze-lvm Version PBVER-rPBREV\n");98 pb_syntax_init("mranalyze-lvm Version PBVER-rPBREV\n"); 92 99 93 100 # Handle options … … 97 104 "verbose|v+" => \$opts{'v'}, 98 105 "quiet|q" => \$opts{'q'}, 106 "output|o=s" => \$opts{'o'}, 99 107 "log-files|l=s" => \$opts{'l'}, 100 108 "version|V" => \$opts{'V'}, … … 128 136 pb_temp_init(); 129 137 130 my $lvmds = "/usr/sbin/lvmdiskscan"; 131 my $lvmproc = "/proc/lvm/global"; 132 my $lvmcmd = "/usr/sbi/lvm"; 138 # -------------------------------- main ----------------------------------- 139 my ($lvmver,$lvmcmd) = mr_lvm_check(); 133 140 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 142 my $OUTPUT = \*STDOUT; 143 if (defined $opts{'o'}) { 144 open(OUTPUT, "> $opts{'o'}") || mr_exit(-1, "Unable to write to $opts{'o'}"); 145 $OUTPUT = \*OUTPUT; 146 } 137 147 138 # Check LVM volumes presence 139 open(LVM,$lvmproc) || mr_exit(-1,"Unable to open $lvmproc"); 148 print $OUTPUT "LVM:$lvmver"; 149 150 # Analyze the existing physical volumes 151 open(LVM,"$lvmcmd pvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd pvdisplay -c"); 140 152 while (<LVM>) { 141 mr_exit(1,"No LVM volumes found in $lvmproc") if (/0 VGs 0 PVs 0 LVs/);153 print $OUTPUT "PV:$_"; 142 154 } 143 155 close(LVM); 144 156 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 158 open(LVM,"$lvmcmd vgdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd vgdisplay -c"); 148 159 while (<LVM>) { 149 if (/Logical Volume Manager/ || /LVM version:/) { 150 $lvmver = $_; 151 $lvmver =~ s/:([0-9])\..*/$1/; 152 } 160 print $OUTPUT "VG:$_"; 153 161 } 154 162 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 163 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 165 open(LVM,"$lvmcmd lvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd lvdisplay -c"); 194 166 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"; 167 print $OUTPUT "LV:$_"; 197 168 } 198 169 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 170 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"; 171 mr_exit(0,undef); 172 173 sub mr_exit { 174 175 my $code = shift; 176 my $msg = shift; 177 178 close(OUTPUT); 179 print $msg."\n" if ((defined $msg) and ($pbdebug >= 0)); 180 die "ERROR returned\n" if ($code < 0); 181 print "No LVM handling\n" if (($code > 0) and ($pbdebug >= 0)); 182 exit($code); 218 183 } 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 WriteShutdownScript241 mr_exit(0,"End of analyze-lvm");
Note:
See TracChangeset
for help on using the changeset viewer.