source: devel/mindi/sbin/mranalyze-lvm @ 2119

Last change on this file since 2119 was 2119, checked in by Bruno Cornec, 12 years ago

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

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1#!/usr/bin/perl -w
2#
3# Analyze the LVM configuration
4# and store 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
30mranalyze-lvm - A Mindi Tool to analyze the LVM configuration and store it
31
32=head1 DESCRIPTION
33
34B<mranalyze-lvm> prints all the information related to the LVM configuration that may be used by a restoration process
35
36=head1 SYNOPSIS
37
38mranalyze-lvm [-v]|[-q]|[-h]|[--man][-o outputfile][-l logfile]
39
40=head1 OPTIONS
41
42=over 4
43
44=item B<-v|--verbose>
45
46Be more verbose
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
60=item B<-o|--output>
61
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
69
70=back
71
72=head1 WEB SITES
73
74The 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/>.
75
76=head1 USER MAILING LIST
77
78The mailing list of the project is available at L<mailto:mondo@lists.sf.net>
79 
80=head1 AUTHORS
81
82The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
83
84=head1 COPYRIGHT
85
86Analyze-LVM is distributed under the GPL v2.0 license
87described in the file C<COPYING> included with the distribution.
88
89=cut
90
91
92# ---------------------------------------------------------------------------
93# Globals
94my %opts;                   # CLI Options
95
96# Initialize the syntax string
97
98pb_syntax_init("mranalyze-lvm Version PBVER-rPBREV\n");
99
100# Handle options
101#
102GetOptions("help|?|h" => \$opts{'h'}, 
103        "man" => \$opts{'man'},
104        "verbose|v+" => \$opts{'v'},
105        "quiet|q" => \$opts{'q'},
106        "output|o=s" => \$opts{'o'},
107        "log-files|l=s" => \$opts{'l'},
108        "version|V" => \$opts{'V'},
109) || pb_syntax(-1,0);
110
111# easy options
112if (defined $opts{'h'}) {
113    pb_syntax(0,1);
114}
115if (defined $opts{'man'}) {
116    pb_syntax(0,2);
117}
118if (defined $opts{'v'}) {
119    $pbdebug = $opts{'v'};
120}
121if (defined $opts{'q'}) {
122    $pbdebug=-1;
123}
124
125#
126# Global variables
127#
128my $MINDI_VERSION = "PBVER-rPBREV";
129my $MINDI_PREFIX = "PBPREFIX";
130my $MINDI_CONF = "PBCONF";
131my $MINDI_LIB = "PBLIB";
132my $MINDI_SBIN = "$MINDI_PREFIX/sbin";
133#
134# Temp dir
135#
136pb_temp_init();
137
138# -------------------------------- main -----------------------------------
139my ($lvmver,$lvmcmd) = mr_lvm_check();
140
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}
147
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");
152while (<LVM>) {
153        print $OUTPUT "PV:$_";
154}
155close(LVM);
156
157# Analyze the existing volume groups
158open(LVM,"$lvmcmd vgdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd vgdisplay -c");
159while (<LVM>) {
160        print $OUTPUT "VG:$_";
161}
162close(LVM);
163
164# Analyze the existing logical volumes
165open(LVM,"$lvmcmd lvdisplay -c |") || mr_exit(-1,"Unable to execute $lvmcmd lvdisplay -c");
166while (<LVM>) {
167        print $OUTPUT "LV:$_";
168}
169close(LVM);
170
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);
183}
Note: See TracBrowser for help on using the repository browser.