chiark / gitweb /
fixes from testing on chiark
[chiark-utils.git] / backup / snap-common
index c12bc6d..f6e788a 100644 (file)
@@ -29,6 +29,27 @@ esac
 
 #---------- common functions
 
+lvmunmapperdevice () {
+       # turns device=/dev/mapper/... into /dev/<group>/<volume>
+       case "$device" in
+       /dev/mapper/*)
+               device="`printf '%s' "$device" | perl -pe '
+                       s,^/dev/mapper/,,;
+                       die if m,/,;
+                       s,\-\-,!,g;
+                       s,\-,/,g;
+                       s,\!,-,g;
+                       s,^,/dev/,;
+               '`"
+               ;;
+       esac
+}
+
+lvmdevice2vgroup () {
+       vgroup="${device#/dev/}"
+       vgroup="${vgroup%/*}"
+}
+
 lvmdropcore () {
        snmnt="$vardir/snap-mount"
        umount -v "$snmnt" || true
@@ -49,6 +70,7 @@ lvmdropcore () {
 }
 
 lvmextentscore1 () {
+       # vgroup must be set
        vgdisplay_out="$(really vgdisplay -c "$vgroup")"
        extents="$(printf "%s" "$vgdisplay_out" | awk -F: '{print $16}')"
        extsize="$(printf "%s" "$vgdisplay_out" | awk -F: '{print $13}')"
@@ -60,6 +82,7 @@ lvmextentscore2 () {
 }
 
 lvmcreatecore1 () {
+       # vgroup must be set
        lvpath="/dev/$vgroup/$lvm_lv"
        ln -s -- "$lvpath" "$vardir"/snap-device
        sync