chiark / gitweb /
nntpid as found in chiark's /usr/local/bin/nntpid.old, apparently copied from a versi...
[chiark-utils.git] / backup / lvm
index 4d897e7..dd503e7 100755 (executable)
@@ -6,51 +6,12 @@
 #    lvm drop $vardir
 
 set -e
-
-nargs=$#
-opmode="$1"
-vardir="$2"
-device="$3"
-mountpoint="$4"
-
-lvm_lv=chiark-backup
-lvm_lvtools_opts='-A n'
-lvm_lvcreate_opts=
-lvm_lvcreate_args=
-
-test ! -f /etc/chiark-backup/settings.sh || . /etc/chiark-backup/settings.sh
-
-case "$nargs.$opmode" in
-4.snap|2.drop)
-       ;;
-*)
-       cat >&2 <<'END'
-usage: .../lvm snap VARDIR DEV MOUNT
-       .../lvm drop VARDIR
-END
-       exit 1
-       ;;
-esac
-
+snapkind=lvm
+. /usr/share/chiark-backup/snap-common
 
 #---------- clean up anything
 
-snmnt="$vardir/snap-mount"
-umount -v "$snmnt" || true
-test ! -d "$snmnt" || rmdir -- "$snmnt"
-
-set +e
-old_lv_dev="$(readlink $vardir/snap-device)"
-rc=$?
-set -e
-
-if [ $rc = 0 ]; then
-       set +e
-       lvchange    $lvm_lvtools_opts -a n $old_lv_dev
-       lvremove -f $lvm_lvtools_opts      $old_lv_dev
-       set -e
-       rm $vardir/snap-device
-fi
+lvmdropcore
 
 if test "$opmode" = drop; then
        echo 'lvm snap dropped'
@@ -62,19 +23,21 @@ fi
 fstype="$(mount | sed -n \
  "s,^$device on $mountpoint type \([a-z0-9][a-z0-9]*\) .*,-t \1 ,p")"
 
+lvmunmapperdevice
+lvmdevice2vgroup
+
 if [ -z "$lvm_lvsize_opts" ]; then
-       vggroup="${device#/dev/}"
-       vggroup="${vggroup%/*}"
-       vgdisplay_out="$(really vgdisplay -c "$vggroup")"
-       extents="$(printf "%s" "$vgdisplay_out" | awk -F: '{print $16}')"
-       lvm_lvsize_opts="-l $extents"
-fi
+       lvmextentscore1
+
+       lvdisplay_out="$(really lvdisplay -c "$device")"
+       extents2="$(printf "%s" "$lvdisplay_out" | awk -F: '{print $8}')"
+       extents2=$(( $extents2 + ($extents2+9)/10 - 1 ))
 
-lvpath="$(dirname "$device")/$lvm_lv"
+       lvmextentscore2
+fi
 
-ln -s -- "$lvpath" "$vardir"/snap-device
+lvmcreatecore1
 
-sync
 lvcreate -s \
        $lvm_lvtools_opts \
        $lvm_lvsize_opts \