3 ### Establish snapshots of LVM logical volumes
5 ### (c) 2011 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the distorted.org.uk backup suite.
12 ### distorted-backup is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### distorted-backup is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License along
23 ### with distorted-backup; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ###--------------------------------------------------------------------------
30 ### Parse the command line.
32 ## Provide help or version information.
33 usage="usage: $quis DEVICE [KEY=VALUE ...]"
34 version="$quis, version 1.0.0"
36 0,*) echo >&2 "$usage"; exit 1 ;;
37 *,-v | *,--version) echo "$version"; exit ;;
44 op=OPERATION \`snap' to create snapshot, or \`unsnap' to remove.
45 snapsz=SIZE Size to reserve for snapshot storage.
46 tag=TAG Disambiguation tag to append to logical volume name.
52 ## Scan the option keys.
54 Oop=snap Otag=snap Osnapsz=100M
59 *) echo >&2 "$quis: malformed option \`$i'"; exit 1 ;;
62 case "$k" in *.lvm) k=${k%.lvm} ;; ?*.?*) continue ;; esac
64 op | tag | snapsz) eval "O$k=\$v" ;;
65 *) echo >&2 "$quis: unknown option \`$k'"; win=nil ;;
68 case $win in nil) exit 1 ;; esac
70 ## Check the device name.
72 ?*/?*) ;; *) echo >&2 "$quis: device \`$dev' should be VG/LV"; exit 1 ;;
74 vg=${dev%%/*} lv=${dev#*/}
76 ###--------------------------------------------------------------------------
77 ### Take or remove the snapshot.
83 *%*) szarg="extents" ;;
86 lvcreate >/dev/null --snapshot \
94 ## LVM snapshot removal is full of awful bugs, mostly to do with races
95 ## with udev. We have a handy script which does the necessary. May it
96 ## not be needed for long.
97 lvm-rmsnap >/dev/null "$vg/$lv.$Otag"
101 echo >&2 "$quis: unknown operation \`$Oop'"
107 ###----- That's all, folks --------------------------------------------------