From bac3eb26dd785974c433a92c61c01ab754b03a23 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Wed, 25 Mar 2009 19:23:45 -0400 Subject: [PATCH 1/1] lvmanip: handle second-segment failures svn path=/trunk/scripts/pv-fixup/; revision=2274 --- lvmanip | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lvmanip b/lvmanip index aad381f..0bd06af 100644 --- a/lvmanip +++ b/lvmanip @@ -20,6 +20,10 @@ getfirstblock () { lvinfo () { perl -ne 'print if ( /^(\s*)'"$1"' \{/ ... /^$1\}/ )' $ARCHIVE } +segment2 () { + perl -ne 'print if ( /^(\s*)segment2 \{/ ... /^$1\}/ )' +} + # Generate a dd command to copy the LV data to /dev/xenvg/$lv # Only works for single-segment LVs. @@ -40,3 +44,23 @@ ddlv () { skip=$(( $offset * 64 + 3 )) bs=64K count=$(( $length * 64 )) fi } + +# Generate a dd command to copy the LV data for the second segment. +ddlv2 () { + lvname="$1" + if ! lvinfo $lvname | grep -q 'segment_count = 2'; then + echo "# WARNING: LV $lvname has other than two segments, skipping" >&2 + return 1 + fi + offset=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/"pv0", ([0-9]+)/)') + length=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/extent_count = ([0-9]+)/)') + seek=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/start_extent = ([0-9]+)/)') + + if [ -z "$offset" ]; then + echo "# WARNING: LV $lvname not found"; + else + echo "# Extracting $lvname segment 2 from offset $offset PEs with length $length PEs" + echo dd if=$DISK of=/dev/xenvg/$lvname bs=64K \ + skip=$(($offset*64 + 3)) count=$(($length*64)) seek=$(($seek*64)) + fi +} -- 1.7.9.5