4 DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489
6 # The name of the LVM archive to get data from
7 ARCHIVE=/etc/lvm/archive/xenvg_01514.vg
10 perl -ne 'print if ( /^(\s*)'"$1"' [\{[]/ ... /^$1[\}\]]/ )'
13 perl -lne 'print $1 if (/'"$1"' = ([0-9]+)/)'
17 perl -ne 'print if ( /^(\s*)'"$1"' \{/ ... /^$1\}/ )' $ARCHIVE
20 perl -ne 'print if ( /^(\s*)segment2 \{/ ... /^$1\}/ )'
23 # Extract the first block of an lv to a file named part-$lv
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";
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;
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)
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
51 # Get a list of LVs in an LVM archive
53 cat $ARCHIVE | lvmextractsection "logical_volumes" | tail -n +2 | perl -lne 'if (/^(\s+)\S+\s+{/) { $indent ||= $1; }; print "$1" if /^$indent(\S+)\s+{/;'
57 # Generate a dd command to copy the LV data to /dev/xenvg/$lv
58 # Only works for single-segment LVs.
61 if ! lvinfo $lvname | grep -q 'segment_count = 1'; then
62 echo "# WARNING: LV $lvname has more than one segment, skipping" >&2
65 offset=$(lvinfo $lvname | perl -lne 'print $1 if (/"pv0", ([0-9]+)/)')
66 length=$(lvinfo $lvname | perl -lne 'print $1 if (/extent_count = ([0-9]+)/)')
68 if [ -z "$offset" ]; then
69 echo "# WARNING: LV $lvname not found";
71 echo "# Extracting $lvname from offset $offset PEs with length $length PEs"
72 echo dd if=$DISK of=/dev/xenvg/$lvname \
73 skip=$(( $offset * 64 + 3 )) bs=64K count=$(( $length * 64 ))
77 # Generate a dd command to copy the LV data for the second segment.
80 if ! lvinfo $lvname | grep -q 'segment_count = 2'; then
81 echo "# WARNING: LV $lvname has other than two segments, skipping" >&2
84 offset=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/"pv0", ([0-9]+)/)')
85 length=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/extent_count = ([0-9]+)/)')
86 seek=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/start_extent = ([0-9]+)/)')
88 if [ -z "$offset" ]; then
89 echo "# WARNING: LV $lvname not found";
91 echo "# Extracting $lvname segment 2 from offset $offset PEs with length $length PEs"
92 echo dd if=$DISK of=/dev/xenvg/$lvname bs=64K \
93 skip=$(($offset*64 + 3)) count=$(($length*64)) seek=$(($seek*64))