Changeset 2285
- Timestamp:
- Apr 1, 2009, 12:32:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/pv-fixup/lvmanip
r2274 r2285 5 5 6 6 # The name of the LVM archive to get data from 7 ARCHIVE=/etc/lvm/archive/xenvg_0 0685.vg7 ARCHIVE=/etc/lvm/archive/xenvg_01514.vg 8 8 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 9 lvmextractsection () { 10 perl -ne 'print if ( /^(\s*)'"$1"' [\{[]/ ... /^$1[\}\]]/ )' 11 } 12 lvmextractint () { 13 perl -lne 'print $1 if (/'"$1"' = ([0-9]+)/)' 18 14 } 19 15 … … 23 19 segment2 () { 24 20 perl -ne 'print if ( /^(\s*)segment2 \{/ ... /^$1\}/ )' 21 } 22 23 # Extract the first block of an lv to a file named part-$lv 24 getfirstblock () { 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 39 if /bin/false; then 40 # Usage: 41 mkdir new 42 mkdir 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 46 diff -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 49 fi 50 51 # Get a list of LVs in an LVM archive 52 listlvs () { 53 cat $ARCHIVE | lvmextractsection "logical_volumes" | tail -n +2 | perl -lne 'if (/^(\s+)\S+\s+{/) { $indent ||= $1; }; print "$1" if /^$indent(\S+)\s+{/;' 25 54 } 26 55
Note: See TracChangeset
for help on using the changeset viewer.