source: trunk/scripts/pv-fixup/lvmanip @ 2276

Last change on this file since 2276 was 2274, checked in by price, 16 years ago

lvmanip: handle second-segment failures

File size: 2.2 KB
Line 
1#!/bin/bash
2exit 1
3
4DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489
5
6# The name of the LVM archive to get data from
7ARCHIVE=/etc/lvm/archive/xenvg_00685.vg
8
9# Extract the first block of an lv to a file named part-$lv
10getfirstblock () {
11  lvname="$1"
12  offset=$(grep -A16 $'\t'$lvname $ARCHIVE  | grep pv0 | cut -f 2 -d ,);
13  if [ -z "$offset" ]; then echo "WARNING: LV not found";
14  else
15    echo "Extracting $lvname from offset $offset"
16    dd if=$DISK of=part-$lvname bs=1M skip=$(( $offset * 8192 + 384 )) bs=512 count=1;
17  fi
18}
19
20lvinfo () {
21  perl -ne 'print if ( /^(\s*)'"$1"' \{/ ... /^$1\}/ )' $ARCHIVE
22}
23segment2 () {
24  perl -ne 'print if ( /^(\s*)segment2 \{/ ... /^$1\}/ )'
25}
26
27
28# Generate a dd command to copy the LV data to /dev/xenvg/$lv
29# Only works for single-segment LVs.
30ddlv () {
31  lvname="$1"
32  if ! lvinfo $lvname | grep -q 'segment_count = 1'; then
33    echo "# WARNING: LV $lvname has more than one segment, skipping" >&2
34    return 1
35  fi
36  offset=$(lvinfo $lvname | perl -lne 'print $1 if (/"pv0", ([0-9]+)/)')
37  length=$(lvinfo $lvname | perl -lne 'print $1 if (/extent_count = ([0-9]+)/)')
38
39  if [ -z "$offset" ]; then
40    echo "# WARNING: LV $lvname not found";
41  else
42    echo "# Extracting $lvname from offset $offset PEs with length $length PEs"
43    echo dd if=$DISK of=/dev/xenvg/$lvname \
44      skip=$(( $offset * 64 + 3 )) bs=64K count=$(( $length * 64 ))
45  fi
46}
47
48# Generate a dd command to copy the LV data for the second segment.
49ddlv2 () {
50  lvname="$1"
51  if ! lvinfo $lvname | grep -q 'segment_count = 2'; then
52    echo "# WARNING: LV $lvname has other than two segments, skipping" >&2
53    return 1
54  fi
55  offset=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/"pv0", ([0-9]+)/)')
56  length=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/extent_count = ([0-9]+)/)')
57  seek=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/start_extent = ([0-9]+)/)')
58
59  if [ -z "$offset" ]; then
60    echo "# WARNING: LV $lvname not found";
61  else
62    echo "# Extracting $lvname segment 2 from offset $offset PEs with length $length PEs"
63    echo dd if=$DISK of=/dev/xenvg/$lvname bs=64K \
64      skip=$(($offset*64 + 3)) count=$(($length*64)) seek=$(($seek*64))
65  fi
66}
Note: See TracBrowser for help on using the repository browser.