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-2014
|
---|
9 | # Provided under the GPL v2
|
---|
10 |
|
---|
11 | # Syntax: see below
|
---|
12 |
|
---|
13 | use strict 'vars';
|
---|
14 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
15 | use Data::Dumper;
|
---|
16 | use English;
|
---|
17 | use lib qw (lib);
|
---|
18 | use ProjectBuilder::Base;
|
---|
19 | use ProjectBuilder::Distribution;
|
---|
20 | use MondoRescue::Version;
|
---|
21 | use MondoRescue::Base;
|
---|
22 | use MondoRescue::LVM;
|
---|
23 |
|
---|
24 | =pod
|
---|
25 |
|
---|
26 | =head1 NAME
|
---|
27 |
|
---|
28 | mr-analyze-lvm - A MondoRescue Tool to analyze the LVM configuration and store it
|
---|
29 |
|
---|
30 | =head1 DESCRIPTION
|
---|
31 |
|
---|
32 | B<mr-analyze-lvm> prints all the information related to the LVM configuration that may be used by a restoration process
|
---|
33 |
|
---|
34 | =head1 SYNOPSIS
|
---|
35 |
|
---|
36 | mr-analyze-lvm [-v]|[-q]|[-h]|[--man][-o outputfile][-l logfile]
|
---|
37 |
|
---|
38 | =head1 OPTIONS
|
---|
39 |
|
---|
40 | =over 4
|
---|
41 |
|
---|
42 | =item B<-v|--verbose>
|
---|
43 |
|
---|
44 | Be more verbose
|
---|
45 |
|
---|
46 | =item B<-q|--quiet>
|
---|
47 |
|
---|
48 | Do not print any output.
|
---|
49 |
|
---|
50 | =item B<-h|--help>
|
---|
51 |
|
---|
52 | Print a brief help message and exits.
|
---|
53 |
|
---|
54 | =item B<--man>
|
---|
55 |
|
---|
56 | Prints the manual page and exits.
|
---|
57 |
|
---|
58 | =item B<-o|--output>
|
---|
59 |
|
---|
60 | Name of the file to generate. Use stdout by default
|
---|
61 |
|
---|
62 | The output format is:
|
---|
63 | LVM:lvm-version
|
---|
64 | PV:pv-information as done with pvdisplay -c
|
---|
65 | VG:vg-information as done with vgdisplay -c
|
---|
66 | LV:lv-information as done with lvdisplay -c
|
---|
67 |
|
---|
68 | =back
|
---|
69 |
|
---|
70 | =head1 WEB SITES
|
---|
71 |
|
---|
72 | The 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/>.
|
---|
73 |
|
---|
74 | =head1 USER MAILING LIST
|
---|
75 |
|
---|
76 | The mailing list of the project is available at L<mailto:mondo@lists.sf.net>
|
---|
77 |
|
---|
78 | =head1 AUTHORS
|
---|
79 |
|
---|
80 | The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
|
---|
81 |
|
---|
82 | =head1 COPYRIGHT
|
---|
83 |
|
---|
84 | Analyze-LVM is distributed under the GPL v2.0 license
|
---|
85 | described in the file C<COPYING> included with the distribution.
|
---|
86 |
|
---|
87 | =cut
|
---|
88 |
|
---|
89 |
|
---|
90 | # ---------------------------------------------------------------------------
|
---|
91 | # Globals
|
---|
92 | my %opts; # CLI Options
|
---|
93 |
|
---|
94 | # Initialize the syntax string
|
---|
95 |
|
---|
96 | pb_syntax_init("mr-analyze-lvm Version PBVER-rPBREV\n");
|
---|
97 |
|
---|
98 | # Handle options
|
---|
99 | #
|
---|
100 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
101 | "man" => \$opts{'man'},
|
---|
102 | "verbose|v+" => \$opts{'v'},
|
---|
103 | "quiet|q" => \$opts{'q'},
|
---|
104 | "output|o=s" => \$opts{'o'},
|
---|
105 | "log-files|l=s" => \$opts{'l'},
|
---|
106 | "version|V" => \$opts{'V'},
|
---|
107 | ) || pb_syntax(-1,0);
|
---|
108 |
|
---|
109 | # easy options
|
---|
110 | if (defined $opts{'h'}) {
|
---|
111 | pb_syntax(0,1);
|
---|
112 | }
|
---|
113 | if (defined $opts{'man'}) {
|
---|
114 | pb_syntax(0,2);
|
---|
115 | }
|
---|
116 | if (defined $opts{'v'}) {
|
---|
117 | $pbdebug = $opts{'v'};
|
---|
118 | }
|
---|
119 | if (defined $opts{'q'}) {
|
---|
120 | $pbdebug=-1;
|
---|
121 | }
|
---|
122 |
|
---|
123 | #
|
---|
124 | # Global variables
|
---|
125 | #
|
---|
126 | my $MRMINI_VERSION = "PBVER-rPBREV";
|
---|
127 | my $MRMINI_PREFIX = "PBPREFIX";
|
---|
128 | my $MRMINI_CONF = "PBCONF";
|
---|
129 | my $MRMINI_BIN = "$MRMINI_PREFIX/bin";
|
---|
130 | my $MRMINI_LIB = "$MRMINI_PREFIX/lib";
|
---|
131 |
|
---|
132 | # Init
|
---|
133 | mr_init();
|
---|
134 |
|
---|
135 | # -------------------------------- main -----------------------------------
|
---|
136 | # Where to send the output
|
---|
137 | my $OUTPUT = \*STDOUT;
|
---|
138 | if (defined $opts{'o'}) {
|
---|
139 | open(OUTPUT, "> $opts{'o'}") || mr_exit(-1, "Unable to write to $opts{'o'}");
|
---|
140 | $OUTPUT = \*OUTPUT;
|
---|
141 | }
|
---|
142 |
|
---|
143 | my $lvm = mr_lvm_analyze($OUTPUT);
|
---|
144 |
|
---|
145 | if (not defined $lvm) {
|
---|
146 | pb_log(1,"No LVM handling\n") ;
|
---|
147 | } else {
|
---|
148 | pb_log(1,"LVM Structure :".Dumper($lvm)."\n");
|
---|
149 | }
|
---|
150 |
|
---|
151 | open(LVM, "> /tmp/lvm.out") || mr_exit(-1, "Unable to write to /tmp/lvm.out");
|
---|
152 | $lvm = mr_lvm_analyze(\*LVM);
|
---|
153 | close(LVM);
|
---|
154 | open(LVM, "/tmp/lvm.out") || mr_exit(-1, "Unable to read to /tmp/lvm.out");
|
---|
155 | $lvm = mr_lvm_prepare(\*LVM,$OUTPUT,1);
|
---|
156 | close(LVM);
|
---|
157 |
|
---|
158 | if (defined $opts{'o'}) {
|
---|
159 | close($OUTPUT);
|
---|
160 | }
|
---|
161 | mr_exit(0,undef);
|
---|