Changeset 2285 for trunk


Ignore:
Timestamp:
Apr 1, 2009, 12:32:50 AM (16 years ago)
Author:
quentin
Message:

Update scripts for extracting LVM data

File:
1 edited

Legend:

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

    r2274 r2285  
    55
    66# The name of the LVM archive to get data from
    7 ARCHIVE=/etc/lvm/archive/xenvg_00685.vg
     7ARCHIVE=/etc/lvm/archive/xenvg_01514.vg
    88
    9 # Extract the first block of an lv to a file named part-$lv
    10 getfirstblock () {
    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
     9lvmextractsection () {
     10  perl -ne 'print if ( /^(\s*)'"$1"' [\{[]/ ... /^$1[\}\]]/ )'
     11}
     12lvmextractint () {
     13  perl -lne 'print $1 if (/'"$1"' = ([0-9]+)/)'
    1814}
    1915
     
    2319segment2 () {
    2420  perl -ne 'print if ( /^(\s*)segment2 \{/ ... /^$1\}/ )'
     21}
     22
     23# Extract the first block of an lv to a file named part-$lv
     24getfirstblock () {
     25  lvname="$1"
     26  lvinfo=$(lvinfo "$lvname")
     27  firststripe=$(echo "$lvinfo" | lvmextractsection 'stripes =' | tail -n +2 | head -n 1)
     28  offset=$(echo "$firststripe" | cut -f 2 -d ,);
     29  if [ -z "$offset" ]; then echo "WARNING: LV $lvname not found";
     30  else
     31    pvname=$(echo "$firststripe" | perl -pe 's/.*"([^"]+)".*/\1/')
     32    pvdevice=$(cat $ARCHIVE | lvmextractsection "$pvname" | perl -lne 'print $1 if (/device = "(.+)"/)')
     33    pe_start=$(cat $ARCHIVE | lvmextractsection "$pvname" | lvmextractint "pe_start")
     34    echo "Extracting $lvname from PE offset $offset on $pvname ($pvdevice)"
     35    dd if=$pvdevice of=part-$lvname bs=1M skip=$(( $offset * 8192 + $pe_start )) bs=512 count=1;
     36  fi
     37}
     38
     39if /bin/false; then
     40# Usage:
     41mkdir new
     42mkdir old
     43(cd old; for i in $(listlvs); do getfirstblock "$i"; done)
     44(cd new; for i in $(listlvs); do dd if=/dev/xenvg/$i of=part-$i bs=512 count=1; done)
     45
     46diff -u <(cd old && sfdisk -l * 2>/dev/null) <(cd new && sfdisk -l * 2>/dev/null)
     47(cd old && md5sum *) | (cd new && md5sum -c) | grep -v OK
     48# end usage
     49fi
     50
     51# Get a list of LVs in an LVM archive
     52listlvs () {
     53  cat $ARCHIVE | lvmextractsection "logical_volumes" | tail -n +2 | perl -lne 'if (/^(\s+)\S+\s+{/) { $indent ||= $1; }; print "$1" if /^$indent(\S+)\s+{/;'
    2554}
    2655
Note: See TracChangeset for help on using the changeset viewer.