chiark / gitweb /
c12bc6dcbbbafae0949efde85e7b15f02fec84ff
[chiark-utils.git] / backup / snap-common
1 # sourced by snap/lvm and snap/remountrocp
2
3 #---------- common arg parsing
4
5 nargs=$#
6 opmode="$1"
7 vardir="$2"
8 device="$3"
9 mountpoint="$4"
10
11 lvm_lv=chiark-backup
12 lvm_lvtools_opts='-A n'
13 lvm_lvcreate_opts=
14 lvm_lvcreate_args=
15
16 test ! -f /etc/chiark-backup/settings.sh || . /etc/chiark-backup/settings.sh
17
18 case "$nargs.$opmode" in
19 4.snap|2.drop)
20         ;;
21 *)
22         cat >&2 <<END
23 usage: .../$snapkind snap VARDIR DEV MOUNT
24        .../$snapkind drop VARDIR
25 END
26         exit 1
27         ;;
28 esac
29
30 #---------- common functions
31
32 lvmdropcore () {
33         snmnt="$vardir/snap-mount"
34         umount -v "$snmnt" || true
35         test ! -d "$snmnt" || rmdir -- "$snmnt"
36
37         set +e
38         old_lv_dev="$(readlink $vardir/snap-device)"
39         rc=$?
40         set -e
41
42         if [ $rc = 0 ]; then
43                 set +e
44                 lvchange    $lvm_lvtools_opts -a n $old_lv_dev
45                 lvremove -f $lvm_lvtools_opts      $old_lv_dev
46                 set -e
47                 rm $vardir/snap-device
48         fi
49 }
50
51 lvmextentscore1 () {
52         vgdisplay_out="$(really vgdisplay -c "$vgroup")"
53         extents="$(printf "%s" "$vgdisplay_out" | awk -F: '{print $16}')"
54         extsize="$(printf "%s" "$vgdisplay_out" | awk -F: '{print $13}')"
55 }
56
57 lvmextentscore2 () {
58         if [ $extents2 -lt $extents ]; then extents=$extents2; fi
59         lvm_lvsize_opts="-l $extents"
60 }
61
62 lvmcreatecore1 () {
63         lvpath="/dev/$vgroup/$lvm_lv"
64         ln -s -- "$lvpath" "$vardir"/snap-device
65         sync
66 }