Line | |
---|
1 | #!/bin/bash |
---|
2 | exit 1 |
---|
3 | |
---|
4 | DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489 |
---|
5 | |
---|
6 | # The name of the LVM archive to get data from |
---|
7 | ARCHIVE=/etc/lvm/archive/xenvg_00685.vg |
---|
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 |
---|
18 | } |
---|
19 | |
---|
20 | lvinfo () { |
---|
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. |
---|
26 | ddlv () { |
---|
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 |
---|
42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.