#!/bin/sh # create an lvm snapshot volume and then e2fsck that volume # if it's successful then we set the mount count to 0 and # last fs check time to the timestamp of when we took the # snapshot. # # example: snapfsck /dev/foo_vg/bar_lv 1G # # 1G is the snapshot volume size. # # this code is public domain. # # dean gaudet PATH=/usr/bin:/bin:/usr/sbin:/sbin export PATH if [ $# != 2 ]; then echo "usage: $0 lvname snapsize" 1>&2 exit 1 fi lvname="$1" size="$2" # if we're successful then we'll mark the lv as having been fsck'd # at this time ... we need to sleep into the next second to be # completely accurate. tune2fs -T expects local time. now="`date +%Y%m%d%H%M%S`" sleep 1 snapname=snapfsck$now lvcreate --size "$size" --snapshot --name $snapname "$lvname" || exit 1 snapname="`dirname $lvname`/$snapname" if e2fsck -f -n "$snapname"; then tune2fs -C 0 -T $now "$lvname" fi rc=$? lvremove -f "$snapname" exit $rc