# HG changeset patch # User Matthias Förste # Date 1336126326 -7200 # Node ID 12744a06a554f1fda47e3ef61ed505a3b594535f # Parent fdaedf4749962f030feaa972b6bd6ed8003ace4a should work with any posix shell (not just bash) diff -r fdaedf474996 -r 12744a06a554 Makefile --- a/Makefile Fri May 04 12:08:34 2012 +0200 +++ b/Makefile Fri May 04 12:12:06 2012 +0200 @@ -12,6 +12,6 @@ clean: -rm -f $(objects) -%: %.bash +%: %.sh cp -f $< $@ chmod +x-w $@ diff -r fdaedf474996 -r 12744a06a554 snapfsck.bash --- a/snapfsck.bash Fri May 04 12:08:34 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -#!/bin/bash - -SNAPSIZE='500M' - -warn() { - echo $@ >&2 -} - -die() { - if [ $# -ne 0 ]; then - echo $@ >&2 - else - echo something went wrong - fi - exit -1 -} - -usage() { - -cat <<__U -usage: - $0 [-s snapsize] /dev// - or - $0 [-s snapsize] / - but not (yet?) - $0 [-s snapsize] /dev/mapper/- -__U - -exit -1 - -} - -while getopts "s:" opt; do - case $opt in - s) - SNAPSIZE="$OPTARG" - ;; - \?) - usage - ;; - esac -done -shift $((OPTIND-1)) - -p=${1:?device required} -p=${p#/dev/} -vg=${p%/*} -lv=${p##*/} -lvs="snap.${lv}" - -[ -n "${vg}" -a -n "${lv}" -a "${vg}" != "${p}" -a "${lv}" != "${p}" ] || usage - -d=$(date +%Y%m%d%H%M%S) -lvcreate -n"$lvs" -L"$SNAPSIZE" -s "$vg/$lv" || die -if e2fsck -fp "/dev/$vg/$lvs"; then - tune2fs -C 1 -T "$d" "/dev/$vg/$lv" || die - waittime=1 # second - tries=60 - i=1 - # if you have problems removing volumes then you may have the 'udisks' - # package installed; see: - # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549691#74 - # https://bugzilla.redhat.com/show_bug.cgi?id=577798#c5 - # https://www.redhat.com/archives/linux-lvm/2010-August/msg00029.html - lvremove -f "$vg/$lvs" || die -else - die fsck returned nonzero: this may indicate filesystem corruption on the origin volume. The snapshot has not been removed. -fi diff -r fdaedf474996 -r 12744a06a554 snapfsck.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snapfsck.sh Fri May 04 12:12:06 2012 +0200 @@ -0,0 +1,68 @@ +#!/bin/sh + +SNAPSIZE='500M' + +warn() { + echo $@ >&2 +} + +die() { + if [ $# -ne 0 ]; then + echo $@ >&2 + else + echo something went wrong + fi + exit -1 +} + +usage() { + +cat <<__U +usage: + $0 [-s snapsize] /dev// + or + $0 [-s snapsize] / + but not (yet?) + $0 [-s snapsize] /dev/mapper/- +__U + +exit -1 + +} + +while getopts "s:" opt; do + case $opt in + s) + SNAPSIZE="$OPTARG" + ;; + \?) + usage + ;; + esac +done +shift $((OPTIND-1)) + +p=${1:?device required} +p=${p#/dev/} +vg=${p%/*} +lv=${p##*/} +lvs="snap.${lv}" + +[ -n "${vg}" -a -n "${lv}" -a "${vg}" != "${p}" -a "${lv}" != "${p}" ] || usage + +d=$(date +%Y%m%d%H%M%S) +lvcreate -n"$lvs" -L"$SNAPSIZE" -s "$vg/$lv" || die +if e2fsck -fp "/dev/$vg/$lvs"; then + tune2fs -C 1 -T "$d" "/dev/$vg/$lv" || die + waittime=1 # second + tries=60 + i=1 + # if you have problems removing volumes then you may have the 'udisks' + # package installed; see: + # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549691#74 + # https://bugzilla.redhat.com/show_bug.cgi?id=577798#c5 + # https://www.redhat.com/archives/linux-lvm/2010-August/msg00029.html + lvremove -f "$vg/$lvs" || die +else + die fsck returned nonzero: this may indicate filesystem corruption on the origin volume. The snapshot has not been removed. +fi