LV manipulation shell functions
[invirt/scripts/pv-fixup.git] / lvmanip
diff --git a/lvmanip b/lvmanip
new file mode 100644 (file)
index 0000000..44b61ca
--- /dev/null
+++ b/lvmanip
@@ -0,0 +1,25 @@
+# The name of the LVM archive to get data from
+ARCHIVE=/etc/lvm/archive/xenvg_00685.vg
+
+# Extract the first block of an lv to a file named part-$lv
+getfirstblock () {
+lvname="$1"
+offset=$(grep -A16 $'\t'$lvname $ARCHIVE  | grep pv0 | cut -f 2 -d ,);
+if [ -z "$offset" ]; then echo "WARNING: LV not found";
+else
+echo "Extracting $lvname from offset $offset"
+dd if=/dev/mapper/36090a028407d6e2b2589a45cdb971489 of=part-$lvname bs=1M skip=$(( $offset * 8192 + 384 )) bs=512 count=1;
+fi
+}
+
+# Generate a dd command to copy the lv data to /dev/xenvg/$lv
+ddlv () {
+lvname="$1"
+offset=$(grep -A16 $'\t'$lvname $ARCHIVE  | grep pv0 | cut -f 2 -d ,);
+length=$(( $(grep -A16 $'\t'$lvname $ARCHIVE  | grep extent_count | cut -f 2 -d = | cut -f 1 -d '#') ));
+if [ -z "$offset" ]; then echo "# WARNING: LV $lvname not found";
+else
+echo "#Extracting $lvname from offset $offset with length $length"
+echo dd if=/dev/mapper/36090a028407d6e2b2589a45cdb971489 of=/dev/xenvg/$lvname bs=1M skip=$(( $offset * 8192 + 384 )) ibs=512 obs=4194304 count=$length
+fi
+}