chiark / gitweb /
nntpid as found in chiark's /usr/local/bin/nntpid.old, apparently copied from a versi...
[chiark-utils.git] / backup / lvm
index 3e9cc2b..dd503e7 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # invoked by backup scripts as
 #    lvm snap $vardir $device $mountpoint
 #              creates and mounts on $vardir/snap-mount
@@ -6,50 +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
 
-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'
@@ -61,17 +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
-       df="$(df -k $device)"
-       blocks="$(printf "%s" "$df" |  sed -n '2,$s,^/dev/[^    ]*[     ][      ]*[0-9][0-9]*[  ][      ]*\([0-9][0-9]*\)[      ].*,\1,p')"
-       lvm_lvsize_opts="-L $blocks"K
-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 \