source: MondoRescue/devel/mindi/sbin/mrprepare-lvm@ 2135

Last change on this file since 2135 was 2135, checked in by Bruno Cornec, 15 years ago
  • Improve the pres for DR definition
  • Property svn:executable set to *
File size: 5.5 KB
RevLine 
[2076]1#!/usr/bin/perl -w
2#
3# Analyze the LVM configuration
4# and stor the configuration for restore time
5#
6# $Id$
7#
8# Copyright B. Cornec 2008
9# Provided under the GPL v2
10
11# Syntax: see below
12
13use strict 'vars';
14use Getopt::Long qw(:config auto_abbrev no_ignore_case);
15use Data::Dumper;
16use English;
17use File::Basename;
18use File::Copy;
19use File::stat;
20use File::Temp qw(tempdir);
21use POSIX qw(strftime);
22use lib qw (lib);
23use ProjectBuilder::Base;
24use ProjectBuilder::Distribution;
25
26=pod
27
28=head1 NAME
29
[2119]30mrprepare-lvm - A Mindi Tool to restore the LVM configuration and apply it
[2076]31
32=head1 DESCRIPTION
33
[2119]34B<mrprepare-lvm> gets all the information related to the LVM configuration from stdin or a file and prepare a restoration script
[2076]35
36=head1 SYNOPSIS
37
[2119]38mrprepare-lvm [-v]|[-q]|[-h]|[--man][-i inputfile][-l logfile][-m multiplier]
[2076]39
40=head1 OPTIONS
41
42=over 4
43
44=item B<-v|--verbose>
45
[2119]46Be more verbose
[2076]47
48=item B<-q|--quiet>
49
50Do not print any output.
51
52=item B<-h|--help>
53
54Print a brief help message and exits.
55
56=item B<--man>
57
58Prints the manual page and exits.
59
[2119]60=item B<-i|--input>
[2076]61
[2119]62Name of the file to get input from. Use stdin by default
[2076]63
[2119]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
75
[2076]76=back
77
78=head1 WEB SITES
79
80The main Web site of the project is available at L<http://www.mondorescue.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.mondorescue.org/>.
81
82=head1 USER MAILING LIST
83
[2119]84The mailing list of the project is available at L<mailto:mondo@lists.sf.net>
[2076]85
86=head1 AUTHORS
87
88The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
89
90=head1 COPYRIGHT
91
92Analyze-LVM is distributed under the GPL v2.0 license
93described in the file C<COPYING> included with the distribution.
94
95=cut
96
97
98# ---------------------------------------------------------------------------
[2119]99# Globals
100my %opts; # CLI Options
[2076]101
102# Initialize the syntax string
103
[2119]104pb_syntax_init("mrprepare-lvm Version PBVER-rPBREV\n");
[2076]105
106# Handle options
107#
108GetOptions("help|?|h" => \$opts{'h'},
109 "man" => \$opts{'man'},
110 "verbose|v+" => \$opts{'v'},
111 "quiet|q" => \$opts{'q'},
[2119]112 "input|i=s" => \$opts{'o'},
113 "output|o=s" => \$opts{'o'},
114 "multiplier|m=s" => \$opts{'o'},
[2076]115 "log-files|l=s" => \$opts{'l'},
116 "version|V" => \$opts{'V'},
117) || pb_syntax(-1,0);
118
119# easy options
120if (defined $opts{'h'}) {
121 pb_syntax(0,1);
122}
123if (defined $opts{'man'}) {
124 pb_syntax(0,2);
125}
126if (defined $opts{'v'}) {
127 $pbdebug = $opts{'v'};
128}
129if (defined $opts{'q'}) {
[2119]130 $pbdebug = -1;
[2076]131}
[2119]132my $mrmult = 1;
133if (defined $opts{'m'}) {
134 $mrmult = $opts{'m'};
135}
[2076]136
137#
138# Global variables
139#
140my $MINDI_VERSION = "PBVER-rPBREV";
141my $MINDI_PREFIX = "PBPREFIX";
142my $MINDI_CONF = "PBCONF";
143my $MINDI_LIB = "PBLIB";
144my $MINDI_SBIN = "$MINDI_PREFIX/sbin";
145#
146# Temp dir
147#
148pb_temp_init();
149
150# -------------------------------- main -----------------------------------
[2119]151my ($lvmver,$lvmcmd) = mr_lvm_check();
[2076]152
[2119]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;
[2076]158}
159
[2119]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;
[2076]165}
166
[2119]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";
[2076]187 }
[2119]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";
[2135]200 $firsttime = 1;
[2119]201 }
202 my ($tag,$lvname,$vgname,$lvaccess,$lvstat,$lvnum,$oclv,$lvsize,$leinlv,$lealloc,$allocpol,$readahead,$major,$minor) = split(/:/);
203 print $OUTPUT "# Create Logical Volume $lvname\n";
204 print $OUTPUT "$lvmcmd lvcreate -n $lvname -L ".$lvsize*$mrmult." -r $readahead $vgname\n";
205 #[ "$stripes" ] && output="$output -i $stripes"
206 #[ "$stripesize" ] && output="$output -I $stripesize"
[2076]207 }
208}
[2119]209print $OUTPUT "\n";
210print $OUTPUT "# Scanning again Volume Groups\n";
211print $OUTPUT "$lvmcmd vgscan\n";
212print $OUTPUT "\n";
[2076]213
214
[2119]215#WriteShutdownScript
216mr_exit(0,"End of mrprepare-lvm");
[2076]217
[2119]218sub mr_exit {
[2076]219
[2119]220my $code = shift;
221my $msg = shift || "";
[2076]222
[2119]223close(OUTPUT);
224print $msg."\n";
225die "ERROR returned\n" if ($code < 0);
226print "No LVM handling\n" if ($code > 0);
227exit(0);
[2076]228}
Note: See TracBrowser for help on using the repository browser.