Changeset 2273


Ignore:
Timestamp:
Mar 24, 2009, 11:58:22 PM (16 years ago)
Author:
price
Message:

lvmanip tweaks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/pv-fixup/lvmanip

    r2271 r2273  
     1#!/bin/bash
     2exit 1
     3
     4DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489
     5
    16# The name of the LVM archive to get data from
    27ARCHIVE=/etc/lvm/archive/xenvg_00685.vg
     
    49# Extract the first block of an lv to a file named part-$lv
    510getfirstblock () {
    6 lvname="$1"
    7 offset=$(grep -A16 $'\t'$lvname $ARCHIVE  | grep pv0 | cut -f 2 -d ,);
    8 if [ -z "$offset" ]; then echo "WARNING: LV not found";
    9 else
    10 echo "Extracting $lvname from offset $offset"
    11 dd if=/dev/mapper/36090a028407d6e2b2589a45cdb971489 of=part-$lvname bs=1M skip=$(( $offset * 8192 + 384 )) bs=512 count=1;
    12 fi
     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
    1318}
    1419
    15 # Generate a dd command to copy the lv data to /dev/xenvg/$lv
     20lvinfo () {
     21  perl -ne 'print if ( /^(\s*)'"$1"' \{/ ... /^$1\}/ )' $ARCHIVE
     22}
     23
     24# Generate a dd command to copy the LV data to /dev/xenvg/$lv
     25# Only works for single-segment LVs.
    1626ddlv () {
    17 lvname="$1"
    18 offset=$(grep -A16 $'\t'$lvname $ARCHIVE  | grep pv0 | cut -f 2 -d ,);
    19 length=$(( $(grep -A16 $'\t'$lvname $ARCHIVE  | grep extent_count | cut -f 2 -d = | cut -f 1 -d '#') ));
    20 if [ -z "$offset" ]; then echo "# WARNING: LV $lvname not found";
    21 else
    22 echo "#Extracting $lvname from offset $offset with length $length"
    23 echo dd if=/dev/mapper/36090a028407d6e2b2589a45cdb971489 of=/dev/xenvg/$lvname bs=1M skip=$(( $offset * 8192 + 384 )) ibs=512 obs=4194304 count=$length
    24 fi
     27  lvname="$1"
     28  if ! lvinfo $lvname | grep -q 'segment_count = 1'; then
     29    echo "# WARNING: LV $lvname has more than one segment, skipping" >&2
     30    return 1
     31  fi
     32  offset=$(lvinfo $lvname | perl -lne 'print $1 if (/"pv0", ([0-9]+)/)')
     33  length=$(lvinfo $lvname | perl -lne 'print $1 if (/extent_count = ([0-9]+)/)')
     34
     35  if [ -z "$offset" ]; then
     36    echo "# WARNING: LV $lvname not found";
     37  else
     38    echo "# Extracting $lvname from offset $offset PEs with length $length PEs"
     39    echo dd if=$DISK of=/dev/xenvg/$lvname \
     40      skip=$(( $offset * 64 + 3 )) bs=64K count=$(( $length * 64 ))
     41  fi
    2542}
Note: See TracChangeset for help on using the changeset viewer.