#! /bin/sh ### ### Establish snapshots of LVM logical volumes ### ### (c) 2011 Mark Wooding ### ###----- Licensing notice --------------------------------------------------- ### ### This program is free software; you can redistribute it and/or modify ### it under the terms of the GNU General Public License as published by ### the Free Software Foundation; either version 2 of the License, or ### (at your option) any later version. ### ### This program is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU General Public License for more details. ### ### You should have received a copy of the GNU General Public License ### along with this program; if not, write to the Free Software Foundation, ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. set -e quis=${0##*/} ###-------------------------------------------------------------------------- ### Parse the command line. ## Provide help or version information. usage="usage: $quis DEVICE [KEY=VALUE ...]" version="$quis, version 1.0.0" case "$#,$1" in 0,*) echo >&2 "$usage"; exit 1 ;; *,-v | *,--version) echo "$version"; exit ;; *,-h | *,--help) cat <&2 "$quis: malformed option \`$i'"; exit 1 ;; esac k=${i%%=*} v=${i#*=} case "$k" in *.lvm) k=${k%.lvm} ;; ?*.?*) continue ;; esac case "$k" in op | tag | snapsz) eval "O$k=\$v" ;; *) echo >&2 "$quis: unknown option \`$k'"; win=nil ;; esac done case $win in nil) exit 1 ;; esac ## Check the device name. case "$dev" in ?*/?*) ;; *) echo >&2 "$quis: device \`$dev' should be VG/LV"; exit 1 ;; esac vg=${dev%%/*} lv=${dev#*/} ###-------------------------------------------------------------------------- ### Take or remove the snapshot. case "$Oop" in snap) case "$Osnapsz" in *%*) szarg="extents" ;; *) szarg="size" ;; esac lvcreate >/dev/null --snapshot \ --$szarg="$Osnapsz" \ --name="$lv.$Otag" \ "$vg/$lv" echo "$vg/$lv.$Otag" ;; unsnap) ## LVM snapshot removal is full of awful bugs, mostly to do with races ## with udev. We have a handy script which does the necessary. May it ## not be needed for long. lvm-rmsnap >/dev/null "$vg/$lv.$Otag" ;; *) echo >&2 "$quis: unknown operation \`$Oop'" exit 1 ;; esac ###----- That's all, folks --------------------------------------------------