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