chiark / gitweb /
do not placate -Wpointer-sign
[chiark-utils.git] / backup / lvm
1 #!/bin/bash
2 # invoked by backup scripts as
3 #    lvm snap $vardir $device $mountpoint
4 #               creates and mounts on $vardir/snap-mount
5 #               creates $vardir/snap-device -> device
6 #    lvm drop $vardir
7
8 set -e
9 snapkind=lvm
10 . /usr/share/chiark-backup/snap-common
11
12 #---------- clean up anything
13
14 lvmdropcore
15
16 if test "$opmode" = drop; then
17         echo 'lvm snap dropped'
18         exit 0
19 fi
20
21 #---------- create snapshot
22
23 fstype="$(mount | sed -n \
24  "s,^$device on $mountpoint type \([a-z0-9][a-z0-9]*\) .*,-t \1 ,p")"
25
26 lvmunmapperdevice
27 lvmdevice2vgroup
28
29 if [ -z "$lvm_lvsize_opts" ]; then
30         lvmextentscore1
31
32         lvdisplay_out="$(really lvdisplay -c "$device")"
33         extents2="$(printf "%s" "$lvdisplay_out" | awk -F: '{print $8}')"
34         extents2=$(( $extents2 + ($extents2+9)/10 - 1 ))
35
36         lvmextentscore2
37 fi
38
39 lvmcreatecore1
40
41 lvcreate -s \
42         $lvm_lvtools_opts \
43         $lvm_lvsize_opts \
44         -n $lvm_lv \
45         $lvm_lvcreate_opts "$device" $lvm_lvcreate_args
46
47 mkdir -- "$snmnt"
48 mount -v -r $fstype $lvm_mount_opts "$lvpath" "$snmnt"
49
50 echo 'lvm snap activated'