- Timestamp:
- Jan 12, 2009, 1:53:26 PM (16 years ago)
- Location:
- devel/mindi/sbin
- Files:
-
- 1 deleted
- 2 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"); -
devel/mindi/sbin/mrprepare-lvm
r2090 r2119 28 28 =head1 NAME 29 29 30 Analyze-lvm - A Mindi Tool to analyze the LVM configuration and storeit30 mrprepare-lvm - A Mindi Tool to restore the LVM configuration and apply 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<mrprepare-lvm> gets all the information related to the LVM configuration from stdin or a file and prepare a restoration script 35 35 36 36 =head1 SYNOPSIS 37 37 38 analyze-lvm [-v]|[-q]|[-h]|[--man]38 mrprepare-lvm [-v]|[-q]|[-h]|[--man][-i inputfile][-l logfile][-m multiplier] 39 39 40 40 =head1 OPTIONS … … 44 44 =item B<-v|--verbose> 45 45 46 Be more verbose 47 48 =item B<-q|--quiet> 49 50 Do not print any output. 51 52 =item B<-h|--help> 53 46 54 Print a brief help message and exits. 47 55 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 57 56 =item B<--man> 58 57 59 58 Prints the manual page and exits. 60 59 61 =item B<-i|--iso iso_image> 62 63 Name of the ISO image you want to created. 60 =item B<-i|--input> 61 62 Name of the file to get input from. Use stdin by default 63 64 The input 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 69 70 =item B<-o|--output> 71 72 Name of the file to write output to. Use stdout by default. 73 The output file is a srpit ready to run in order to setup correctly LVM 74 64 75 65 76 =back … … 71 82 =head1 USER MAILING LIST 72 83 73 The m iling list of the project is available at L<mailto:mondo@lists.sf.net>84 The mailing list of the project is available at L<mailto:mondo@lists.sf.net> 74 85 75 86 =head1 AUTHORS … … 86 97 87 98 # --------------------------------------------------------------------------- 99 # Globals 100 my %opts; # CLI Options 88 101 89 102 # Initialize the syntax string 90 103 91 pb_syntax_init(" analyze-lvm Version PBVER-rPBREV\n");104 pb_syntax_init("mrprepare-lvm Version PBVER-rPBREV\n"); 92 105 93 106 # Handle options … … 97 110 "verbose|v+" => \$opts{'v'}, 98 111 "quiet|q" => \$opts{'q'}, 112 "input|i=s" => \$opts{'o'}, 113 "output|o=s" => \$opts{'o'}, 114 "multiplier|m=s" => \$opts{'o'}, 99 115 "log-files|l=s" => \$opts{'l'}, 100 116 "version|V" => \$opts{'V'}, … … 112 128 } 113 129 if (defined $opts{'q'}) { 114 $pbdebug=-1; 130 $pbdebug = -1; 131 } 132 my $mrmult = 1; 133 if (defined $opts{'m'}) { 134 $mrmult = $opts{'m'}; 115 135 } 116 136 … … 128 148 pb_temp_init(); 129 149 130 my $lvmds = "/usr/sbin/lvmdiskscan";131 my $lvmproc = "/proc/lvm/global";132 my $lvmcmd = "/usr/sbi/lvm";133 134 150 # -------------------------------- 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/; 151 my ($lvmver,$lvmcmd) = mr_lvm_check(); 152 153 # Where to send the output 154 my $OUTPUT = \*STDOUT; 155 if (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 161 my $INPUT = \*STDIN; 162 if (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 171 print $OUTPUT "# Desactivate Volume Groups\n"; 172 print $OUTPUT "$lvmcmd vgchange -an\n"; 173 print $OUTPUT "\n"; 174 175 my $firsttime = 0; 176 while (<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"; 152 187 } 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"; 170 200 } 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" 172 206 } 173 207 } 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"); 208 print $OUTPUT "\n"; 209 print $OUTPUT "# Scanning again Volume Groups\n"; 210 print $OUTPUT "$lvmcmd vgscan\n"; 211 print $OUTPUT "\n"; 212 213 214 #WriteShutdownScript 215 mr_exit(0,"End of mrprepare-lvm"); 216 217 sub mr_exit { 218 219 my $code = shift; 220 my $msg = shift || ""; 221 222 close(OUTPUT); 223 print $msg."\n"; 224 die "ERROR returned\n" if ($code < 0); 225 print "No LVM handling\n" if ($code > 0); 226 exit(0); 227 }
Note:
See TracChangeset
for help on using the changeset viewer.